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..63a1e2bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: objective-c osx_image: xcode7 -xcode_workspace: LFLiveKit.xcworkspace +xcode_project: FrameWork/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 FrameWork/LFLiveKit.xcodeproj -scheme 'LFLiveKit' -configuration Release -sdk iphonesimulator -arch i386 build \ No newline at end of file diff --git a/LFLiveKit/Info.plist b/FrameWork/Info.plist similarity index 97% rename from LFLiveKit/Info.plist rename to FrameWork/Info.plist index f1ed6f98..f4d50a8c 100644 --- a/LFLiveKit/Info.plist +++ b/FrameWork/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.6.4 + 2.6 CFBundleSignature ???? CFBundleVersion diff --git a/FrameWork/LFLiveKit.xcodeproj/project.pbxproj b/FrameWork/LFLiveKit.xcodeproj/project.pbxproj new file mode 100644 index 00000000..74b3450d --- /dev/null +++ b/FrameWork/LFLiveKit.xcodeproj/project.pbxproj @@ -0,0 +1,2726 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXAggregateTarget section */ + 84D003751DB8FE1000560583 /* LFLiveKitFramework-universal */ = { + isa = PBXAggregateTarget; + buildConfigurationList = 84D003761DB8FE1000560583 /* Build configuration list for PBXAggregateTarget "LFLiveKitFramework-universal" */; + buildPhases = ( + 84D0037B1DB8FE1C00560583 /* ShellScript */, + ); + dependencies = ( + 84D0037A1DB8FE1800560583 /* PBXTargetDependency */, + ); + name = "LFLiveKitFramework-universal"; + productName = "LFLiveKitFramework-universal"; + }; +/* End PBXAggregateTarget section */ + +/* Begin PBXBuildFile section */ + 84358FF41DD1FEB600811FC7 /* GLProgram.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358E871DD1FEB500811FC7 /* GLProgram.h */; }; + 84358FF51DD1FEB600811FC7 /* GLProgram.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E881DD1FEB500811FC7 /* GLProgram.m */; }; + 84358FF61DD1FEB600811FC7 /* GPUImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358E891DD1FEB500811FC7 /* GPUImage.h */; }; + 84358FF71DD1FEB600811FC7 /* GPUImage3x3ConvolutionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358E8A1DD1FEB500811FC7 /* GPUImage3x3ConvolutionFilter.h */; }; + 84358FF81DD1FEB600811FC7 /* GPUImage3x3ConvolutionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E8B1DD1FEB500811FC7 /* GPUImage3x3ConvolutionFilter.m */; }; + 84358FF91DD1FEB600811FC7 /* GPUImage3x3TextureSamplingFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358E8C1DD1FEB500811FC7 /* GPUImage3x3TextureSamplingFilter.h */; }; + 84358FFA1DD1FEB600811FC7 /* GPUImage3x3TextureSamplingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E8D1DD1FEB500811FC7 /* GPUImage3x3TextureSamplingFilter.m */; }; + 84358FFB1DD1FEB600811FC7 /* GPUImageAdaptiveThresholdFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358E8E1DD1FEB500811FC7 /* GPUImageAdaptiveThresholdFilter.h */; }; + 84358FFC1DD1FEB600811FC7 /* GPUImageAdaptiveThresholdFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E8F1DD1FEB500811FC7 /* GPUImageAdaptiveThresholdFilter.m */; }; + 84358FFD1DD1FEB600811FC7 /* GPUImageAddBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358E901DD1FEB500811FC7 /* GPUImageAddBlendFilter.h */; }; + 84358FFE1DD1FEB600811FC7 /* GPUImageAddBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E911DD1FEB500811FC7 /* GPUImageAddBlendFilter.m */; }; + 84358FFF1DD1FEB600811FC7 /* GPUImageAlphaBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358E921DD1FEB500811FC7 /* GPUImageAlphaBlendFilter.h */; }; + 843590001DD1FEB600811FC7 /* GPUImageAlphaBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E931DD1FEB500811FC7 /* GPUImageAlphaBlendFilter.m */; }; + 843590011DD1FEB600811FC7 /* GPUImageAmatorkaFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358E941DD1FEB500811FC7 /* GPUImageAmatorkaFilter.h */; }; + 843590021DD1FEB600811FC7 /* GPUImageAmatorkaFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E951DD1FEB500811FC7 /* GPUImageAmatorkaFilter.m */; }; + 843590031DD1FEB600811FC7 /* GPUImageAverageColor.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358E961DD1FEB500811FC7 /* GPUImageAverageColor.h */; }; + 843590041DD1FEB600811FC7 /* GPUImageAverageColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E971DD1FEB500811FC7 /* GPUImageAverageColor.m */; }; + 843590051DD1FEB600811FC7 /* GPUImageAverageLuminanceThresholdFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358E981DD1FEB500811FC7 /* GPUImageAverageLuminanceThresholdFilter.h */; }; + 843590061DD1FEB600811FC7 /* GPUImageAverageLuminanceThresholdFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E991DD1FEB500811FC7 /* GPUImageAverageLuminanceThresholdFilter.m */; }; + 843590071DD1FEB600811FC7 /* GPUImageBilateralFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358E9A1DD1FEB500811FC7 /* GPUImageBilateralFilter.h */; }; + 843590081DD1FEB600811FC7 /* GPUImageBilateralFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E9B1DD1FEB500811FC7 /* GPUImageBilateralFilter.m */; }; + 843590091DD1FEB600811FC7 /* GPUImageBoxBlurFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358E9C1DD1FEB500811FC7 /* GPUImageBoxBlurFilter.h */; }; + 8435900A1DD1FEB600811FC7 /* GPUImageBoxBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E9D1DD1FEB500811FC7 /* GPUImageBoxBlurFilter.m */; }; + 8435900B1DD1FEB600811FC7 /* GPUImageBrightnessFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358E9E1DD1FEB500811FC7 /* GPUImageBrightnessFilter.h */; }; + 8435900C1DD1FEB600811FC7 /* GPUImageBrightnessFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E9F1DD1FEB500811FC7 /* GPUImageBrightnessFilter.m */; }; + 8435900D1DD1FEB600811FC7 /* GPUImageBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EA01DD1FEB500811FC7 /* GPUImageBuffer.h */; }; + 8435900E1DD1FEB600811FC7 /* GPUImageBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EA11DD1FEB500811FC7 /* GPUImageBuffer.m */; }; + 8435900F1DD1FEB600811FC7 /* GPUImageBulgeDistortionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EA21DD1FEB500811FC7 /* GPUImageBulgeDistortionFilter.h */; }; + 843590101DD1FEB600811FC7 /* GPUImageBulgeDistortionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EA31DD1FEB500811FC7 /* GPUImageBulgeDistortionFilter.m */; }; + 843590111DD1FEB600811FC7 /* GPUImageCannyEdgeDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EA41DD1FEB500811FC7 /* GPUImageCannyEdgeDetectionFilter.h */; }; + 843590121DD1FEB600811FC7 /* GPUImageCannyEdgeDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EA51DD1FEB500811FC7 /* GPUImageCannyEdgeDetectionFilter.m */; }; + 843590131DD1FEB600811FC7 /* GPUImageCGAColorspaceFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EA61DD1FEB500811FC7 /* GPUImageCGAColorspaceFilter.h */; }; + 843590141DD1FEB600811FC7 /* GPUImageCGAColorspaceFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EA71DD1FEB500811FC7 /* GPUImageCGAColorspaceFilter.m */; }; + 843590151DD1FEB600811FC7 /* GPUImageChromaKeyBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EA81DD1FEB500811FC7 /* GPUImageChromaKeyBlendFilter.h */; }; + 843590161DD1FEB600811FC7 /* GPUImageChromaKeyBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EA91DD1FEB500811FC7 /* GPUImageChromaKeyBlendFilter.m */; }; + 843590171DD1FEB600811FC7 /* GPUImageChromaKeyFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EAA1DD1FEB500811FC7 /* GPUImageChromaKeyFilter.h */; }; + 843590181DD1FEB600811FC7 /* GPUImageChromaKeyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EAB1DD1FEB500811FC7 /* GPUImageChromaKeyFilter.m */; }; + 843590191DD1FEB600811FC7 /* GPUImageClosingFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EAC1DD1FEB500811FC7 /* GPUImageClosingFilter.h */; }; + 8435901A1DD1FEB600811FC7 /* GPUImageClosingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EAD1DD1FEB500811FC7 /* GPUImageClosingFilter.m */; }; + 8435901B1DD1FEB600811FC7 /* GPUImageColorBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EAE1DD1FEB500811FC7 /* GPUImageColorBlendFilter.h */; }; + 8435901C1DD1FEB600811FC7 /* GPUImageColorBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EAF1DD1FEB500811FC7 /* GPUImageColorBlendFilter.m */; }; + 8435901D1DD1FEB600811FC7 /* GPUImageColorBurnBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EB01DD1FEB500811FC7 /* GPUImageColorBurnBlendFilter.h */; }; + 8435901E1DD1FEB600811FC7 /* GPUImageColorBurnBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EB11DD1FEB500811FC7 /* GPUImageColorBurnBlendFilter.m */; }; + 8435901F1DD1FEB600811FC7 /* GPUImageColorConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EB21DD1FEB500811FC7 /* GPUImageColorConversion.h */; }; + 843590201DD1FEB600811FC7 /* GPUImageColorConversion.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EB31DD1FEB500811FC7 /* GPUImageColorConversion.m */; }; + 843590211DD1FEB600811FC7 /* GPUImageColorDodgeBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EB41DD1FEB500811FC7 /* GPUImageColorDodgeBlendFilter.h */; }; + 843590221DD1FEB600811FC7 /* GPUImageColorDodgeBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EB51DD1FEB500811FC7 /* GPUImageColorDodgeBlendFilter.m */; }; + 843590231DD1FEB600811FC7 /* GPUImageColorInvertFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EB61DD1FEB500811FC7 /* GPUImageColorInvertFilter.h */; }; + 843590241DD1FEB600811FC7 /* GPUImageColorInvertFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EB71DD1FEB500811FC7 /* GPUImageColorInvertFilter.m */; }; + 843590251DD1FEB600811FC7 /* GPUImageColorLocalBinaryPatternFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EB81DD1FEB500811FC7 /* GPUImageColorLocalBinaryPatternFilter.h */; }; + 843590261DD1FEB600811FC7 /* GPUImageColorLocalBinaryPatternFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EB91DD1FEB500811FC7 /* GPUImageColorLocalBinaryPatternFilter.m */; }; + 843590271DD1FEB600811FC7 /* GPUImageColorMatrixFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EBA1DD1FEB500811FC7 /* GPUImageColorMatrixFilter.h */; }; + 843590281DD1FEB600811FC7 /* GPUImageColorMatrixFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EBB1DD1FEB500811FC7 /* GPUImageColorMatrixFilter.m */; }; + 843590291DD1FEB600811FC7 /* GPUImageColorPackingFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EBC1DD1FEB500811FC7 /* GPUImageColorPackingFilter.h */; }; + 8435902A1DD1FEB600811FC7 /* GPUImageColorPackingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EBD1DD1FEB500811FC7 /* GPUImageColorPackingFilter.m */; }; + 8435902B1DD1FEB600811FC7 /* GPUImageColourFASTFeatureDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EBE1DD1FEB500811FC7 /* GPUImageColourFASTFeatureDetector.h */; }; + 8435902C1DD1FEB600811FC7 /* GPUImageColourFASTFeatureDetector.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EBF1DD1FEB500811FC7 /* GPUImageColourFASTFeatureDetector.m */; }; + 8435902D1DD1FEB600811FC7 /* GPUImageColourFASTSamplingOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EC01DD1FEB500811FC7 /* GPUImageColourFASTSamplingOperation.h */; }; + 8435902E1DD1FEB600811FC7 /* GPUImageColourFASTSamplingOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EC11DD1FEB500811FC7 /* GPUImageColourFASTSamplingOperation.m */; }; + 8435902F1DD1FEB600811FC7 /* GPUImageContrastFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EC21DD1FEB500811FC7 /* GPUImageContrastFilter.h */; }; + 843590301DD1FEB600811FC7 /* GPUImageContrastFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EC31DD1FEB500811FC7 /* GPUImageContrastFilter.m */; }; + 843590311DD1FEB600811FC7 /* GPUImageCropFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EC41DD1FEB500811FC7 /* GPUImageCropFilter.h */; }; + 843590321DD1FEB600811FC7 /* GPUImageCropFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EC51DD1FEB500811FC7 /* GPUImageCropFilter.m */; }; + 843590331DD1FEB600811FC7 /* GPUImageCrosshairGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EC61DD1FEB500811FC7 /* GPUImageCrosshairGenerator.h */; }; + 843590341DD1FEB600811FC7 /* GPUImageCrosshairGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EC71DD1FEB500811FC7 /* GPUImageCrosshairGenerator.m */; }; + 843590351DD1FEB600811FC7 /* GPUImageCrosshatchFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EC81DD1FEB500811FC7 /* GPUImageCrosshatchFilter.h */; }; + 843590361DD1FEB600811FC7 /* GPUImageCrosshatchFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EC91DD1FEB500811FC7 /* GPUImageCrosshatchFilter.m */; }; + 843590371DD1FEB600811FC7 /* GPUImageDarkenBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358ECA1DD1FEB500811FC7 /* GPUImageDarkenBlendFilter.h */; }; + 843590381DD1FEB600811FC7 /* GPUImageDarkenBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ECB1DD1FEB500811FC7 /* GPUImageDarkenBlendFilter.m */; }; + 843590391DD1FEB600811FC7 /* GPUImageDifferenceBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358ECC1DD1FEB500811FC7 /* GPUImageDifferenceBlendFilter.h */; }; + 8435903A1DD1FEB600811FC7 /* GPUImageDifferenceBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ECD1DD1FEB500811FC7 /* GPUImageDifferenceBlendFilter.m */; }; + 8435903B1DD1FEB600811FC7 /* GPUImageDilationFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358ECE1DD1FEB500811FC7 /* GPUImageDilationFilter.h */; }; + 8435903C1DD1FEB600811FC7 /* GPUImageDilationFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ECF1DD1FEB500811FC7 /* GPUImageDilationFilter.m */; }; + 8435903D1DD1FEB600811FC7 /* GPUImageDirectionalNonMaximumSuppressionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358ED01DD1FEB500811FC7 /* GPUImageDirectionalNonMaximumSuppressionFilter.h */; }; + 8435903E1DD1FEB600811FC7 /* GPUImageDirectionalNonMaximumSuppressionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ED11DD1FEB500811FC7 /* GPUImageDirectionalNonMaximumSuppressionFilter.m */; }; + 8435903F1DD1FEB600811FC7 /* GPUImageDirectionalSobelEdgeDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358ED21DD1FEB500811FC7 /* GPUImageDirectionalSobelEdgeDetectionFilter.h */; }; + 843590401DD1FEB600811FC7 /* GPUImageDirectionalSobelEdgeDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ED31DD1FEB500811FC7 /* GPUImageDirectionalSobelEdgeDetectionFilter.m */; }; + 843590411DD1FEB600811FC7 /* GPUImageDissolveBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358ED41DD1FEB500811FC7 /* GPUImageDissolveBlendFilter.h */; }; + 843590421DD1FEB600811FC7 /* GPUImageDissolveBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ED51DD1FEB500811FC7 /* GPUImageDissolveBlendFilter.m */; }; + 843590431DD1FEB600811FC7 /* GPUImageDivideBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358ED61DD1FEB500811FC7 /* GPUImageDivideBlendFilter.h */; }; + 843590441DD1FEB600811FC7 /* GPUImageDivideBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ED71DD1FEB500811FC7 /* GPUImageDivideBlendFilter.m */; }; + 843590451DD1FEB600811FC7 /* GPUImageEmbossFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358ED81DD1FEB500811FC7 /* GPUImageEmbossFilter.h */; }; + 843590461DD1FEB600811FC7 /* GPUImageEmbossFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ED91DD1FEB500811FC7 /* GPUImageEmbossFilter.m */; }; + 843590471DD1FEB600811FC7 /* GPUImageErosionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EDA1DD1FEB500811FC7 /* GPUImageErosionFilter.h */; }; + 843590481DD1FEB600811FC7 /* GPUImageErosionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EDB1DD1FEB500811FC7 /* GPUImageErosionFilter.m */; }; + 843590491DD1FEB600811FC7 /* GPUImageExclusionBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EDC1DD1FEB500811FC7 /* GPUImageExclusionBlendFilter.h */; }; + 8435904A1DD1FEB600811FC7 /* GPUImageExclusionBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EDD1DD1FEB500811FC7 /* GPUImageExclusionBlendFilter.m */; }; + 8435904B1DD1FEB600811FC7 /* GPUImageExposureFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EDE1DD1FEB500811FC7 /* GPUImageExposureFilter.h */; }; + 8435904C1DD1FEB600811FC7 /* GPUImageExposureFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EDF1DD1FEB500811FC7 /* GPUImageExposureFilter.m */; }; + 8435904D1DD1FEB600811FC7 /* GPUImageFalseColorFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EE01DD1FEB500811FC7 /* GPUImageFalseColorFilter.h */; }; + 8435904E1DD1FEB600811FC7 /* GPUImageFalseColorFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EE11DD1FEB500811FC7 /* GPUImageFalseColorFilter.m */; }; + 8435904F1DD1FEB600811FC7 /* GPUImageFASTCornerDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EE21DD1FEB500811FC7 /* GPUImageFASTCornerDetectionFilter.h */; }; + 843590501DD1FEB600811FC7 /* GPUImageFASTCornerDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EE31DD1FEB500811FC7 /* GPUImageFASTCornerDetectionFilter.m */; }; + 843590511DD1FEB600811FC7 /* GPUImageFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EE41DD1FEB500811FC7 /* GPUImageFilter.h */; }; + 843590521DD1FEB600811FC7 /* GPUImageFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EE51DD1FEB500811FC7 /* GPUImageFilter.m */; }; + 843590531DD1FEB600811FC7 /* GPUImageFilterGroup.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EE61DD1FEB500811FC7 /* GPUImageFilterGroup.h */; }; + 843590541DD1FEB600811FC7 /* GPUImageFilterGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EE71DD1FEB500811FC7 /* GPUImageFilterGroup.m */; }; + 843590551DD1FEB600811FC7 /* GPUImageFilterPipeline.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EE81DD1FEB500811FC7 /* GPUImageFilterPipeline.h */; }; + 843590561DD1FEB600811FC7 /* GPUImageFilterPipeline.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EE91DD1FEB500811FC7 /* GPUImageFilterPipeline.m */; }; + 843590571DD1FEB600811FC7 /* GPUImageFourInputFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EEA1DD1FEB500811FC7 /* GPUImageFourInputFilter.h */; }; + 843590581DD1FEB600811FC7 /* GPUImageFourInputFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EEB1DD1FEB500811FC7 /* GPUImageFourInputFilter.m */; }; + 843590591DD1FEB600811FC7 /* GPUImageFramebuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EEC1DD1FEB500811FC7 /* GPUImageFramebuffer.h */; }; + 8435905A1DD1FEB600811FC7 /* GPUImageFramebuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EED1DD1FEB500811FC7 /* GPUImageFramebuffer.m */; }; + 8435905B1DD1FEB600811FC7 /* GPUImageFramebufferCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EEE1DD1FEB500811FC7 /* GPUImageFramebufferCache.h */; }; + 8435905C1DD1FEB600811FC7 /* GPUImageFramebufferCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EEF1DD1FEB500811FC7 /* GPUImageFramebufferCache.m */; }; + 8435905D1DD1FEB600811FC7 /* GPUImageGammaFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EF01DD1FEB500811FC7 /* GPUImageGammaFilter.h */; }; + 8435905E1DD1FEB600811FC7 /* GPUImageGammaFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EF11DD1FEB500811FC7 /* GPUImageGammaFilter.m */; }; + 8435905F1DD1FEB600811FC7 /* GPUImageGaussianBlurFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EF21DD1FEB500811FC7 /* GPUImageGaussianBlurFilter.h */; }; + 843590601DD1FEB600811FC7 /* GPUImageGaussianBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EF31DD1FEB500811FC7 /* GPUImageGaussianBlurFilter.m */; }; + 843590611DD1FEB600811FC7 /* GPUImageGaussianBlurPositionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EF41DD1FEB500811FC7 /* GPUImageGaussianBlurPositionFilter.h */; }; + 843590621DD1FEB600811FC7 /* GPUImageGaussianBlurPositionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EF51DD1FEB500811FC7 /* GPUImageGaussianBlurPositionFilter.m */; }; + 843590631DD1FEB600811FC7 /* GPUImageGaussianSelectiveBlurFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EF61DD1FEB500811FC7 /* GPUImageGaussianSelectiveBlurFilter.h */; }; + 843590641DD1FEB600811FC7 /* GPUImageGaussianSelectiveBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EF71DD1FEB500811FC7 /* GPUImageGaussianSelectiveBlurFilter.m */; }; + 843590651DD1FEB600811FC7 /* GPUImageGlassSphereFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EF81DD1FEB500811FC7 /* GPUImageGlassSphereFilter.h */; }; + 843590661DD1FEB600811FC7 /* GPUImageGlassSphereFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EF91DD1FEB500811FC7 /* GPUImageGlassSphereFilter.m */; }; + 843590671DD1FEB600811FC7 /* GPUImageGrayscaleFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EFA1DD1FEB500811FC7 /* GPUImageGrayscaleFilter.h */; }; + 843590681DD1FEB600811FC7 /* GPUImageGrayscaleFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EFB1DD1FEB500811FC7 /* GPUImageGrayscaleFilter.m */; }; + 843590691DD1FEB600811FC7 /* GPUImageHalftoneFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EFC1DD1FEB500811FC7 /* GPUImageHalftoneFilter.h */; }; + 8435906A1DD1FEB600811FC7 /* GPUImageHalftoneFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EFD1DD1FEB500811FC7 /* GPUImageHalftoneFilter.m */; }; + 8435906B1DD1FEB600811FC7 /* GPUImageHardLightBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358EFE1DD1FEB500811FC7 /* GPUImageHardLightBlendFilter.h */; }; + 8435906C1DD1FEB600811FC7 /* GPUImageHardLightBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EFF1DD1FEB500811FC7 /* GPUImageHardLightBlendFilter.m */; }; + 8435906D1DD1FEB600811FC7 /* GPUImageHarrisCornerDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F001DD1FEB500811FC7 /* GPUImageHarrisCornerDetectionFilter.h */; }; + 8435906E1DD1FEB600811FC7 /* GPUImageHarrisCornerDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F011DD1FEB500811FC7 /* GPUImageHarrisCornerDetectionFilter.m */; }; + 8435906F1DD1FEB600811FC7 /* GPUImageHazeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F021DD1FEB500811FC7 /* GPUImageHazeFilter.h */; }; + 843590701DD1FEB600811FC7 /* GPUImageHazeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F031DD1FEB500811FC7 /* GPUImageHazeFilter.m */; }; + 843590711DD1FEB600811FC7 /* GPUImageHighlightShadowFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F041DD1FEB500811FC7 /* GPUImageHighlightShadowFilter.h */; }; + 843590721DD1FEB600811FC7 /* GPUImageHighlightShadowFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F051DD1FEB500811FC7 /* GPUImageHighlightShadowFilter.m */; }; + 843590731DD1FEB600811FC7 /* GPUImageHighlightShadowTintFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F061DD1FEB500811FC7 /* GPUImageHighlightShadowTintFilter.h */; }; + 843590741DD1FEB600811FC7 /* GPUImageHighlightShadowTintFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F071DD1FEB500811FC7 /* GPUImageHighlightShadowTintFilter.m */; }; + 843590751DD1FEB600811FC7 /* GPUImageHighPassFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F081DD1FEB500811FC7 /* GPUImageHighPassFilter.h */; }; + 843590761DD1FEB600811FC7 /* GPUImageHighPassFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F091DD1FEB500811FC7 /* GPUImageHighPassFilter.m */; }; + 843590771DD1FEB600811FC7 /* GPUImageHistogramEqualizationFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F0A1DD1FEB500811FC7 /* GPUImageHistogramEqualizationFilter.h */; }; + 843590781DD1FEB600811FC7 /* GPUImageHistogramEqualizationFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F0B1DD1FEB500811FC7 /* GPUImageHistogramEqualizationFilter.m */; }; + 843590791DD1FEB600811FC7 /* GPUImageHistogramFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F0C1DD1FEB500811FC7 /* GPUImageHistogramFilter.h */; }; + 8435907A1DD1FEB600811FC7 /* GPUImageHistogramFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F0D1DD1FEB500811FC7 /* GPUImageHistogramFilter.m */; }; + 8435907B1DD1FEB600811FC7 /* GPUImageHistogramGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F0E1DD1FEB500811FC7 /* GPUImageHistogramGenerator.h */; }; + 8435907C1DD1FEB600811FC7 /* GPUImageHistogramGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F0F1DD1FEB500811FC7 /* GPUImageHistogramGenerator.m */; }; + 8435907D1DD1FEB600811FC7 /* GPUImageHoughTransformLineDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F101DD1FEB500811FC7 /* GPUImageHoughTransformLineDetector.h */; }; + 8435907E1DD1FEB600811FC7 /* GPUImageHoughTransformLineDetector.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F111DD1FEB500811FC7 /* GPUImageHoughTransformLineDetector.m */; }; + 8435907F1DD1FEB600811FC7 /* GPUImageHSBFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F121DD1FEB500811FC7 /* GPUImageHSBFilter.h */; }; + 843590801DD1FEB600811FC7 /* GPUImageHSBFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F131DD1FEB500811FC7 /* GPUImageHSBFilter.m */; }; + 843590811DD1FEB600811FC7 /* GPUImageHueBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F141DD1FEB500811FC7 /* GPUImageHueBlendFilter.h */; }; + 843590821DD1FEB600811FC7 /* GPUImageHueBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F151DD1FEB500811FC7 /* GPUImageHueBlendFilter.m */; }; + 843590831DD1FEB600811FC7 /* GPUImageHueFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F161DD1FEB500811FC7 /* GPUImageHueFilter.h */; }; + 843590841DD1FEB600811FC7 /* GPUImageHueFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F171DD1FEB500811FC7 /* GPUImageHueFilter.m */; }; + 843590851DD1FEB600811FC7 /* GPUImageiOSBlurFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F181DD1FEB500811FC7 /* GPUImageiOSBlurFilter.h */; }; + 843590861DD1FEB600811FC7 /* GPUImageiOSBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F191DD1FEB500811FC7 /* GPUImageiOSBlurFilter.m */; }; + 843590871DD1FEB600811FC7 /* GPUImageJFAVoronoiFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F1A1DD1FEB500811FC7 /* GPUImageJFAVoronoiFilter.h */; }; + 843590881DD1FEB600811FC7 /* GPUImageJFAVoronoiFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F1B1DD1FEB500811FC7 /* GPUImageJFAVoronoiFilter.m */; }; + 843590891DD1FEB600811FC7 /* GPUImageKuwaharaFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F1C1DD1FEB500811FC7 /* GPUImageKuwaharaFilter.h */; }; + 8435908A1DD1FEB600811FC7 /* GPUImageKuwaharaFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F1D1DD1FEB500811FC7 /* GPUImageKuwaharaFilter.m */; }; + 8435908B1DD1FEB600811FC7 /* GPUImageKuwaharaRadius3Filter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F1E1DD1FEB500811FC7 /* GPUImageKuwaharaRadius3Filter.h */; }; + 8435908C1DD1FEB600811FC7 /* GPUImageKuwaharaRadius3Filter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F1F1DD1FEB500811FC7 /* GPUImageKuwaharaRadius3Filter.m */; }; + 8435908D1DD1FEB600811FC7 /* GPUImageLanczosResamplingFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F201DD1FEB500811FC7 /* GPUImageLanczosResamplingFilter.h */; }; + 8435908E1DD1FEB600811FC7 /* GPUImageLanczosResamplingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F211DD1FEB500811FC7 /* GPUImageLanczosResamplingFilter.m */; }; + 8435908F1DD1FEB600811FC7 /* GPUImageLaplacianFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F221DD1FEB500811FC7 /* GPUImageLaplacianFilter.h */; }; + 843590901DD1FEB600811FC7 /* GPUImageLaplacianFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F231DD1FEB500811FC7 /* GPUImageLaplacianFilter.m */; }; + 843590911DD1FEB600811FC7 /* GPUImageLevelsFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F241DD1FEB500811FC7 /* GPUImageLevelsFilter.h */; }; + 843590921DD1FEB600811FC7 /* GPUImageLevelsFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F251DD1FEB500811FC7 /* GPUImageLevelsFilter.m */; }; + 843590931DD1FEB600811FC7 /* GPUImageLightenBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F261DD1FEB500811FC7 /* GPUImageLightenBlendFilter.h */; }; + 843590941DD1FEB600811FC7 /* GPUImageLightenBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F271DD1FEB500811FC7 /* GPUImageLightenBlendFilter.m */; }; + 843590951DD1FEB600811FC7 /* GPUImageLinearBurnBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F281DD1FEB500811FC7 /* GPUImageLinearBurnBlendFilter.h */; }; + 843590961DD1FEB600811FC7 /* GPUImageLinearBurnBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F291DD1FEB500811FC7 /* GPUImageLinearBurnBlendFilter.m */; }; + 843590971DD1FEB600811FC7 /* GPUImageLineGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F2A1DD1FEB500811FC7 /* GPUImageLineGenerator.h */; }; + 843590981DD1FEB600811FC7 /* GPUImageLineGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F2B1DD1FEB500811FC7 /* GPUImageLineGenerator.m */; }; + 843590991DD1FEB600811FC7 /* GPUImageLocalBinaryPatternFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F2C1DD1FEB500811FC7 /* GPUImageLocalBinaryPatternFilter.h */; }; + 8435909A1DD1FEB600811FC7 /* GPUImageLocalBinaryPatternFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F2D1DD1FEB500811FC7 /* GPUImageLocalBinaryPatternFilter.m */; }; + 8435909B1DD1FEB600811FC7 /* GPUImageLookupFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F2E1DD1FEB500811FC7 /* GPUImageLookupFilter.h */; }; + 8435909C1DD1FEB600811FC7 /* GPUImageLookupFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F2F1DD1FEB500811FC7 /* GPUImageLookupFilter.m */; }; + 8435909D1DD1FEB600811FC7 /* GPUImageLowPassFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F301DD1FEB500811FC7 /* GPUImageLowPassFilter.h */; }; + 8435909E1DD1FEB600811FC7 /* GPUImageLowPassFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F311DD1FEB500811FC7 /* GPUImageLowPassFilter.m */; }; + 8435909F1DD1FEB600811FC7 /* GPUImageLuminanceRangeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F321DD1FEB500811FC7 /* GPUImageLuminanceRangeFilter.h */; }; + 843590A01DD1FEB600811FC7 /* GPUImageLuminanceRangeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F331DD1FEB500811FC7 /* GPUImageLuminanceRangeFilter.m */; }; + 843590A11DD1FEB600811FC7 /* GPUImageLuminanceThresholdFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F341DD1FEB500811FC7 /* GPUImageLuminanceThresholdFilter.h */; }; + 843590A21DD1FEB600811FC7 /* GPUImageLuminanceThresholdFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F351DD1FEB500811FC7 /* GPUImageLuminanceThresholdFilter.m */; }; + 843590A31DD1FEB600811FC7 /* GPUImageLuminosity.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F361DD1FEB500811FC7 /* GPUImageLuminosity.h */; }; + 843590A41DD1FEB600811FC7 /* GPUImageLuminosity.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F371DD1FEB500811FC7 /* GPUImageLuminosity.m */; }; + 843590A51DD1FEB600811FC7 /* GPUImageLuminosityBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F381DD1FEB500811FC7 /* GPUImageLuminosityBlendFilter.h */; }; + 843590A61DD1FEB600811FC7 /* GPUImageLuminosityBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F391DD1FEB500811FC7 /* GPUImageLuminosityBlendFilter.m */; }; + 843590A71DD1FEB600811FC7 /* GPUImageMaskFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F3A1DD1FEB500811FC7 /* GPUImageMaskFilter.h */; }; + 843590A81DD1FEB600811FC7 /* GPUImageMaskFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F3B1DD1FEB500811FC7 /* GPUImageMaskFilter.m */; }; + 843590A91DD1FEB600811FC7 /* GPUImageMedianFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F3C1DD1FEB500811FC7 /* GPUImageMedianFilter.h */; }; + 843590AA1DD1FEB600811FC7 /* GPUImageMedianFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F3D1DD1FEB500811FC7 /* GPUImageMedianFilter.m */; }; + 843590AB1DD1FEB600811FC7 /* GPUImageMissEtikateFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F3E1DD1FEB500811FC7 /* GPUImageMissEtikateFilter.h */; }; + 843590AC1DD1FEB600811FC7 /* GPUImageMissEtikateFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F3F1DD1FEB500811FC7 /* GPUImageMissEtikateFilter.m */; }; + 843590AD1DD1FEB600811FC7 /* GPUImageMonochromeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F401DD1FEB500811FC7 /* GPUImageMonochromeFilter.h */; }; + 843590AE1DD1FEB600811FC7 /* GPUImageMonochromeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F411DD1FEB500811FC7 /* GPUImageMonochromeFilter.m */; }; + 843590AF1DD1FEB600811FC7 /* GPUImageMosaicFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F421DD1FEB500811FC7 /* GPUImageMosaicFilter.h */; }; + 843590B01DD1FEB600811FC7 /* GPUImageMosaicFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F431DD1FEB500811FC7 /* GPUImageMosaicFilter.m */; }; + 843590B11DD1FEB600811FC7 /* GPUImageMotionBlurFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F441DD1FEB500811FC7 /* GPUImageMotionBlurFilter.h */; }; + 843590B21DD1FEB600811FC7 /* GPUImageMotionBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F451DD1FEB500811FC7 /* GPUImageMotionBlurFilter.m */; }; + 843590B31DD1FEB600811FC7 /* GPUImageMotionDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F461DD1FEB500811FC7 /* GPUImageMotionDetector.h */; }; + 843590B41DD1FEB600811FC7 /* GPUImageMotionDetector.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F471DD1FEB500811FC7 /* GPUImageMotionDetector.m */; }; + 843590B51DD1FEB600811FC7 /* GPUImageMovie.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F481DD1FEB500811FC7 /* GPUImageMovie.h */; }; + 843590B61DD1FEB600811FC7 /* GPUImageMovie.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F491DD1FEB500811FC7 /* GPUImageMovie.m */; }; + 843590B71DD1FEB600811FC7 /* GPUImageMovieComposition.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F4A1DD1FEB500811FC7 /* GPUImageMovieComposition.h */; }; + 843590B81DD1FEB600811FC7 /* GPUImageMovieComposition.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F4B1DD1FEB500811FC7 /* GPUImageMovieComposition.m */; }; + 843590B91DD1FEB600811FC7 /* GPUImageMultiplyBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F4C1DD1FEB500811FC7 /* GPUImageMultiplyBlendFilter.h */; }; + 843590BA1DD1FEB600811FC7 /* GPUImageMultiplyBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F4D1DD1FEB500811FC7 /* GPUImageMultiplyBlendFilter.m */; }; + 843590BB1DD1FEB600811FC7 /* GPUImageNobleCornerDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F4E1DD1FEB500811FC7 /* GPUImageNobleCornerDetectionFilter.h */; }; + 843590BC1DD1FEB600811FC7 /* GPUImageNobleCornerDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F4F1DD1FEB500811FC7 /* GPUImageNobleCornerDetectionFilter.m */; }; + 843590BD1DD1FEB600811FC7 /* GPUImageNonMaximumSuppressionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F501DD1FEB500811FC7 /* GPUImageNonMaximumSuppressionFilter.h */; }; + 843590BE1DD1FEB600811FC7 /* GPUImageNonMaximumSuppressionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F511DD1FEB500811FC7 /* GPUImageNonMaximumSuppressionFilter.m */; }; + 843590BF1DD1FEB600811FC7 /* GPUImageNormalBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F521DD1FEB500811FC7 /* GPUImageNormalBlendFilter.h */; }; + 843590C01DD1FEB600811FC7 /* GPUImageNormalBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F531DD1FEB500811FC7 /* GPUImageNormalBlendFilter.m */; }; + 843590C11DD1FEB600811FC7 /* GPUImageOpacityFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F541DD1FEB500811FC7 /* GPUImageOpacityFilter.h */; }; + 843590C21DD1FEB600811FC7 /* GPUImageOpacityFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F551DD1FEB500811FC7 /* GPUImageOpacityFilter.m */; }; + 843590C31DD1FEB600811FC7 /* GPUImageOpeningFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F561DD1FEB500811FC7 /* GPUImageOpeningFilter.h */; }; + 843590C41DD1FEB600811FC7 /* GPUImageOpeningFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F571DD1FEB500811FC7 /* GPUImageOpeningFilter.m */; }; + 843590C51DD1FEB600811FC7 /* GPUImageOutput.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F581DD1FEB500811FC7 /* GPUImageOutput.h */; }; + 843590C61DD1FEB600811FC7 /* GPUImageOutput.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F591DD1FEB500811FC7 /* GPUImageOutput.m */; }; + 843590C71DD1FEB600811FC7 /* GPUImageOverlayBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F5A1DD1FEB500811FC7 /* GPUImageOverlayBlendFilter.h */; }; + 843590C81DD1FEB600811FC7 /* GPUImageOverlayBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F5B1DD1FEB500811FC7 /* GPUImageOverlayBlendFilter.m */; }; + 843590C91DD1FEB600811FC7 /* GPUImageParallelCoordinateLineTransformFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F5C1DD1FEB500811FC7 /* GPUImageParallelCoordinateLineTransformFilter.h */; }; + 843590CA1DD1FEB600811FC7 /* GPUImageParallelCoordinateLineTransformFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F5D1DD1FEB500811FC7 /* GPUImageParallelCoordinateLineTransformFilter.m */; }; + 843590CB1DD1FEB600811FC7 /* GPUImagePerlinNoiseFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F5E1DD1FEB500811FC7 /* GPUImagePerlinNoiseFilter.h */; }; + 843590CC1DD1FEB600811FC7 /* GPUImagePerlinNoiseFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F5F1DD1FEB500811FC7 /* GPUImagePerlinNoiseFilter.m */; }; + 843590CD1DD1FEB600811FC7 /* GPUImagePinchDistortionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F601DD1FEB500811FC7 /* GPUImagePinchDistortionFilter.h */; }; + 843590CE1DD1FEB600811FC7 /* GPUImagePinchDistortionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F611DD1FEB500811FC7 /* GPUImagePinchDistortionFilter.m */; }; + 843590CF1DD1FEB600811FC7 /* GPUImagePixellateFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F621DD1FEB500811FC7 /* GPUImagePixellateFilter.h */; }; + 843590D01DD1FEB600811FC7 /* GPUImagePixellateFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F631DD1FEB500811FC7 /* GPUImagePixellateFilter.m */; }; + 843590D11DD1FEB600811FC7 /* GPUImagePixellatePositionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F641DD1FEB500811FC7 /* GPUImagePixellatePositionFilter.h */; }; + 843590D21DD1FEB600811FC7 /* GPUImagePixellatePositionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F651DD1FEB500811FC7 /* GPUImagePixellatePositionFilter.m */; }; + 843590D31DD1FEB600811FC7 /* GPUImagePoissonBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F661DD1FEB500811FC7 /* GPUImagePoissonBlendFilter.h */; }; + 843590D41DD1FEB600811FC7 /* GPUImagePoissonBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F671DD1FEB500811FC7 /* GPUImagePoissonBlendFilter.m */; }; + 843590D51DD1FEB600811FC7 /* GPUImagePolarPixellateFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F681DD1FEB500811FC7 /* GPUImagePolarPixellateFilter.h */; }; + 843590D61DD1FEB600811FC7 /* GPUImagePolarPixellateFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F691DD1FEB500811FC7 /* GPUImagePolarPixellateFilter.m */; }; + 843590D71DD1FEB600811FC7 /* GPUImagePolkaDotFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F6A1DD1FEB500811FC7 /* GPUImagePolkaDotFilter.h */; }; + 843590D81DD1FEB600811FC7 /* GPUImagePolkaDotFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F6B1DD1FEB500811FC7 /* GPUImagePolkaDotFilter.m */; }; + 843590D91DD1FEB600811FC7 /* GPUImagePosterizeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F6C1DD1FEB500811FC7 /* GPUImagePosterizeFilter.h */; }; + 843590DA1DD1FEB600811FC7 /* GPUImagePosterizeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F6D1DD1FEB500811FC7 /* GPUImagePosterizeFilter.m */; }; + 843590DB1DD1FEB600811FC7 /* GPUImagePrewittEdgeDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F6E1DD1FEB500811FC7 /* GPUImagePrewittEdgeDetectionFilter.h */; }; + 843590DC1DD1FEB600811FC7 /* GPUImagePrewittEdgeDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F6F1DD1FEB500811FC7 /* GPUImagePrewittEdgeDetectionFilter.m */; }; + 843590DD1DD1FEB600811FC7 /* GPUImageRawDataInput.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F701DD1FEB500811FC7 /* GPUImageRawDataInput.h */; }; + 843590DE1DD1FEB600811FC7 /* GPUImageRawDataInput.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F711DD1FEB500811FC7 /* GPUImageRawDataInput.m */; }; + 843590DF1DD1FEB600811FC7 /* GPUImageRawDataOutput.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F721DD1FEB500811FC7 /* GPUImageRawDataOutput.h */; }; + 843590E01DD1FEB600811FC7 /* GPUImageRawDataOutput.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F731DD1FEB500811FC7 /* GPUImageRawDataOutput.m */; }; + 843590E11DD1FEB600811FC7 /* GPUImageRGBClosingFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F741DD1FEB500811FC7 /* GPUImageRGBClosingFilter.h */; }; + 843590E21DD1FEB600811FC7 /* GPUImageRGBClosingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F751DD1FEB500811FC7 /* GPUImageRGBClosingFilter.m */; }; + 843590E31DD1FEB600811FC7 /* GPUImageRGBDilationFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F761DD1FEB500811FC7 /* GPUImageRGBDilationFilter.h */; }; + 843590E41DD1FEB600811FC7 /* GPUImageRGBDilationFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F771DD1FEB500811FC7 /* GPUImageRGBDilationFilter.m */; }; + 843590E51DD1FEB600811FC7 /* GPUImageRGBErosionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F781DD1FEB500811FC7 /* GPUImageRGBErosionFilter.h */; }; + 843590E61DD1FEB600811FC7 /* GPUImageRGBErosionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F791DD1FEB500811FC7 /* GPUImageRGBErosionFilter.m */; }; + 843590E71DD1FEB600811FC7 /* GPUImageRGBFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F7A1DD1FEB500811FC7 /* GPUImageRGBFilter.h */; }; + 843590E81DD1FEB600811FC7 /* GPUImageRGBFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F7B1DD1FEB500811FC7 /* GPUImageRGBFilter.m */; }; + 843590E91DD1FEB600811FC7 /* GPUImageRGBOpeningFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F7C1DD1FEB500811FC7 /* GPUImageRGBOpeningFilter.h */; }; + 843590EA1DD1FEB600811FC7 /* GPUImageRGBOpeningFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F7D1DD1FEB500811FC7 /* GPUImageRGBOpeningFilter.m */; }; + 843590EB1DD1FEB600811FC7 /* GPUImageSaturationBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F7E1DD1FEB500811FC7 /* GPUImageSaturationBlendFilter.h */; }; + 843590EC1DD1FEB600811FC7 /* GPUImageSaturationBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F7F1DD1FEB500811FC7 /* GPUImageSaturationBlendFilter.m */; }; + 843590ED1DD1FEB600811FC7 /* GPUImageSaturationFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F801DD1FEB500811FC7 /* GPUImageSaturationFilter.h */; }; + 843590EE1DD1FEB600811FC7 /* GPUImageSaturationFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F811DD1FEB500811FC7 /* GPUImageSaturationFilter.m */; }; + 843590EF1DD1FEB600811FC7 /* GPUImageScreenBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F821DD1FEB500811FC7 /* GPUImageScreenBlendFilter.h */; }; + 843590F01DD1FEB600811FC7 /* GPUImageScreenBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F831DD1FEB500811FC7 /* GPUImageScreenBlendFilter.m */; }; + 843590F11DD1FEB600811FC7 /* GPUImageSepiaFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F841DD1FEB500811FC7 /* GPUImageSepiaFilter.h */; }; + 843590F21DD1FEB600811FC7 /* GPUImageSepiaFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F851DD1FEB500811FC7 /* GPUImageSepiaFilter.m */; }; + 843590F31DD1FEB600811FC7 /* GPUImageSharpenFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F861DD1FEB500811FC7 /* GPUImageSharpenFilter.h */; }; + 843590F41DD1FEB600811FC7 /* GPUImageSharpenFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F871DD1FEB500811FC7 /* GPUImageSharpenFilter.m */; }; + 843590F51DD1FEB600811FC7 /* GPUImageShiTomasiFeatureDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F881DD1FEB500811FC7 /* GPUImageShiTomasiFeatureDetectionFilter.h */; }; + 843590F61DD1FEB600811FC7 /* GPUImageShiTomasiFeatureDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F891DD1FEB500811FC7 /* GPUImageShiTomasiFeatureDetectionFilter.m */; }; + 843590F71DD1FEB600811FC7 /* GPUImageSingleComponentGaussianBlurFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F8A1DD1FEB500811FC7 /* GPUImageSingleComponentGaussianBlurFilter.h */; }; + 843590F81DD1FEB600811FC7 /* GPUImageSingleComponentGaussianBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F8B1DD1FEB600811FC7 /* GPUImageSingleComponentGaussianBlurFilter.m */; }; + 843590F91DD1FEB600811FC7 /* GPUImageSketchFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F8C1DD1FEB600811FC7 /* GPUImageSketchFilter.h */; }; + 843590FA1DD1FEB600811FC7 /* GPUImageSketchFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F8D1DD1FEB600811FC7 /* GPUImageSketchFilter.m */; }; + 843590FB1DD1FEB600811FC7 /* GPUImageSkinToneFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F8E1DD1FEB600811FC7 /* GPUImageSkinToneFilter.h */; }; + 843590FC1DD1FEB600811FC7 /* GPUImageSkinToneFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F8F1DD1FEB600811FC7 /* GPUImageSkinToneFilter.m */; }; + 843590FD1DD1FEB600811FC7 /* GPUImageSmoothToonFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F901DD1FEB600811FC7 /* GPUImageSmoothToonFilter.h */; }; + 843590FE1DD1FEB600811FC7 /* GPUImageSmoothToonFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F911DD1FEB600811FC7 /* GPUImageSmoothToonFilter.m */; }; + 843590FF1DD1FEB600811FC7 /* GPUImageSobelEdgeDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F921DD1FEB600811FC7 /* GPUImageSobelEdgeDetectionFilter.h */; }; + 843591001DD1FEB600811FC7 /* GPUImageSobelEdgeDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F931DD1FEB600811FC7 /* GPUImageSobelEdgeDetectionFilter.m */; }; + 843591011DD1FEB600811FC7 /* GPUImageSoftEleganceFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F941DD1FEB600811FC7 /* GPUImageSoftEleganceFilter.h */; }; + 843591021DD1FEB600811FC7 /* GPUImageSoftEleganceFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F951DD1FEB600811FC7 /* GPUImageSoftEleganceFilter.m */; }; + 843591031DD1FEB600811FC7 /* GPUImageSoftLightBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F961DD1FEB600811FC7 /* GPUImageSoftLightBlendFilter.h */; }; + 843591041DD1FEB600811FC7 /* GPUImageSoftLightBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F971DD1FEB600811FC7 /* GPUImageSoftLightBlendFilter.m */; }; + 843591051DD1FEB600811FC7 /* GPUImageSolarizeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F981DD1FEB600811FC7 /* GPUImageSolarizeFilter.h */; }; + 843591061DD1FEB600811FC7 /* GPUImageSolarizeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F991DD1FEB600811FC7 /* GPUImageSolarizeFilter.m */; }; + 843591071DD1FEB600811FC7 /* GPUImageSolidColorGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F9A1DD1FEB600811FC7 /* GPUImageSolidColorGenerator.h */; }; + 843591081DD1FEB600811FC7 /* GPUImageSolidColorGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F9B1DD1FEB600811FC7 /* GPUImageSolidColorGenerator.m */; }; + 843591091DD1FEB600811FC7 /* GPUImageSourceOverBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F9C1DD1FEB600811FC7 /* GPUImageSourceOverBlendFilter.h */; }; + 8435910A1DD1FEB600811FC7 /* GPUImageSourceOverBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F9D1DD1FEB600811FC7 /* GPUImageSourceOverBlendFilter.m */; }; + 8435910B1DD1FEB600811FC7 /* GPUImageSphereRefractionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358F9E1DD1FEB600811FC7 /* GPUImageSphereRefractionFilter.h */; }; + 8435910C1DD1FEB600811FC7 /* GPUImageSphereRefractionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F9F1DD1FEB600811FC7 /* GPUImageSphereRefractionFilter.m */; }; + 8435910D1DD1FEB600811FC7 /* GPUImageStillCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FA01DD1FEB600811FC7 /* GPUImageStillCamera.h */; }; + 8435910E1DD1FEB600811FC7 /* GPUImageStillCamera.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FA11DD1FEB600811FC7 /* GPUImageStillCamera.m */; }; + 8435910F1DD1FEB600811FC7 /* GPUImageStretchDistortionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FA21DD1FEB600811FC7 /* GPUImageStretchDistortionFilter.h */; }; + 843591101DD1FEB600811FC7 /* GPUImageStretchDistortionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FA31DD1FEB600811FC7 /* GPUImageStretchDistortionFilter.m */; }; + 843591111DD1FEB600811FC7 /* GPUImageSubtractBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FA41DD1FEB600811FC7 /* GPUImageSubtractBlendFilter.h */; }; + 843591121DD1FEB600811FC7 /* GPUImageSubtractBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FA51DD1FEB600811FC7 /* GPUImageSubtractBlendFilter.m */; }; + 843591131DD1FEB600811FC7 /* GPUImageSwirlFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FA61DD1FEB600811FC7 /* GPUImageSwirlFilter.h */; }; + 843591141DD1FEB600811FC7 /* GPUImageSwirlFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FA71DD1FEB600811FC7 /* GPUImageSwirlFilter.m */; }; + 843591151DD1FEB600811FC7 /* GPUImageTextureInput.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FA81DD1FEB600811FC7 /* GPUImageTextureInput.h */; }; + 843591161DD1FEB600811FC7 /* GPUImageTextureInput.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FA91DD1FEB600811FC7 /* GPUImageTextureInput.m */; }; + 843591171DD1FEB600811FC7 /* GPUImageTextureOutput.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FAA1DD1FEB600811FC7 /* GPUImageTextureOutput.h */; }; + 843591181DD1FEB600811FC7 /* GPUImageTextureOutput.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FAB1DD1FEB600811FC7 /* GPUImageTextureOutput.m */; }; + 843591191DD1FEB600811FC7 /* GPUImageThreeInputFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FAC1DD1FEB600811FC7 /* GPUImageThreeInputFilter.h */; }; + 8435911A1DD1FEB600811FC7 /* GPUImageThreeInputFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FAD1DD1FEB600811FC7 /* GPUImageThreeInputFilter.m */; }; + 8435911B1DD1FEB600811FC7 /* GPUImageThresholdEdgeDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FAE1DD1FEB600811FC7 /* GPUImageThresholdEdgeDetectionFilter.h */; }; + 8435911C1DD1FEB600811FC7 /* GPUImageThresholdEdgeDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FAF1DD1FEB600811FC7 /* GPUImageThresholdEdgeDetectionFilter.m */; }; + 8435911D1DD1FEB600811FC7 /* GPUImageThresholdedNonMaximumSuppressionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FB01DD1FEB600811FC7 /* GPUImageThresholdedNonMaximumSuppressionFilter.h */; }; + 8435911E1DD1FEB600811FC7 /* GPUImageThresholdedNonMaximumSuppressionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FB11DD1FEB600811FC7 /* GPUImageThresholdedNonMaximumSuppressionFilter.m */; }; + 8435911F1DD1FEB600811FC7 /* GPUImageThresholdSketchFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FB21DD1FEB600811FC7 /* GPUImageThresholdSketchFilter.h */; }; + 843591201DD1FEB600811FC7 /* GPUImageThresholdSketchFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FB31DD1FEB600811FC7 /* GPUImageThresholdSketchFilter.m */; }; + 843591211DD1FEB600811FC7 /* GPUImageTiltShiftFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FB41DD1FEB600811FC7 /* GPUImageTiltShiftFilter.h */; }; + 843591221DD1FEB600811FC7 /* GPUImageTiltShiftFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FB51DD1FEB600811FC7 /* GPUImageTiltShiftFilter.m */; }; + 843591231DD1FEB600811FC7 /* GPUImageToneCurveFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FB61DD1FEB600811FC7 /* GPUImageToneCurveFilter.h */; }; + 843591241DD1FEB600811FC7 /* GPUImageToneCurveFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FB71DD1FEB600811FC7 /* GPUImageToneCurveFilter.m */; }; + 843591251DD1FEB600811FC7 /* GPUImageToonFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FB81DD1FEB600811FC7 /* GPUImageToonFilter.h */; }; + 843591261DD1FEB600811FC7 /* GPUImageToonFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FB91DD1FEB600811FC7 /* GPUImageToonFilter.m */; }; + 843591271DD1FEB600811FC7 /* GPUImageTransformFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FBA1DD1FEB600811FC7 /* GPUImageTransformFilter.h */; }; + 843591281DD1FEB600811FC7 /* GPUImageTransformFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FBB1DD1FEB600811FC7 /* GPUImageTransformFilter.m */; }; + 843591291DD1FEB600811FC7 /* GPUImageTwoInputCrossTextureSamplingFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FBC1DD1FEB600811FC7 /* GPUImageTwoInputCrossTextureSamplingFilter.h */; }; + 8435912A1DD1FEB600811FC7 /* GPUImageTwoInputCrossTextureSamplingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FBD1DD1FEB600811FC7 /* GPUImageTwoInputCrossTextureSamplingFilter.m */; }; + 8435912B1DD1FEB600811FC7 /* GPUImageTwoInputFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FBE1DD1FEB600811FC7 /* GPUImageTwoInputFilter.h */; }; + 8435912C1DD1FEB600811FC7 /* GPUImageTwoInputFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FBF1DD1FEB600811FC7 /* GPUImageTwoInputFilter.m */; }; + 8435912D1DD1FEB600811FC7 /* GPUImageTwoPassFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FC01DD1FEB600811FC7 /* GPUImageTwoPassFilter.h */; }; + 8435912E1DD1FEB600811FC7 /* GPUImageTwoPassFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FC11DD1FEB600811FC7 /* GPUImageTwoPassFilter.m */; }; + 8435912F1DD1FEB600811FC7 /* GPUImageTwoPassTextureSamplingFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FC21DD1FEB600811FC7 /* GPUImageTwoPassTextureSamplingFilter.h */; }; + 843591301DD1FEB600811FC7 /* GPUImageTwoPassTextureSamplingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FC31DD1FEB600811FC7 /* GPUImageTwoPassTextureSamplingFilter.m */; }; + 843591311DD1FEB600811FC7 /* GPUImageUIElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FC41DD1FEB600811FC7 /* GPUImageUIElement.h */; }; + 843591321DD1FEB600811FC7 /* GPUImageUIElement.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FC51DD1FEB600811FC7 /* GPUImageUIElement.m */; }; + 843591331DD1FEB600811FC7 /* GPUImageUnsharpMaskFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FC61DD1FEB600811FC7 /* GPUImageUnsharpMaskFilter.h */; }; + 843591341DD1FEB600811FC7 /* GPUImageUnsharpMaskFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FC71DD1FEB600811FC7 /* GPUImageUnsharpMaskFilter.m */; }; + 843591351DD1FEB600811FC7 /* GPUImageVideoCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FC81DD1FEB600811FC7 /* GPUImageVideoCamera.h */; }; + 843591361DD1FEB600811FC7 /* GPUImageVideoCamera.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FC91DD1FEB600811FC7 /* GPUImageVideoCamera.m */; }; + 843591371DD1FEB600811FC7 /* GPUImageVignetteFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FCA1DD1FEB600811FC7 /* GPUImageVignetteFilter.h */; }; + 843591381DD1FEB600811FC7 /* GPUImageVignetteFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FCB1DD1FEB600811FC7 /* GPUImageVignetteFilter.m */; }; + 843591391DD1FEB600811FC7 /* GPUImageVoronoiConsumerFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FCC1DD1FEB600811FC7 /* GPUImageVoronoiConsumerFilter.h */; }; + 8435913A1DD1FEB600811FC7 /* GPUImageVoronoiConsumerFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FCD1DD1FEB600811FC7 /* GPUImageVoronoiConsumerFilter.m */; }; + 8435913B1DD1FEB600811FC7 /* GPUImageWeakPixelInclusionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FCE1DD1FEB600811FC7 /* GPUImageWeakPixelInclusionFilter.h */; }; + 8435913C1DD1FEB600811FC7 /* GPUImageWeakPixelInclusionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FCF1DD1FEB600811FC7 /* GPUImageWeakPixelInclusionFilter.m */; }; + 8435913D1DD1FEB600811FC7 /* GPUImageWhiteBalanceFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FD01DD1FEB600811FC7 /* GPUImageWhiteBalanceFilter.h */; }; + 8435913E1DD1FEB600811FC7 /* GPUImageWhiteBalanceFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FD11DD1FEB600811FC7 /* GPUImageWhiteBalanceFilter.m */; }; + 8435913F1DD1FEB600811FC7 /* GPUImageXYDerivativeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FD21DD1FEB600811FC7 /* GPUImageXYDerivativeFilter.h */; }; + 843591401DD1FEB600811FC7 /* GPUImageXYDerivativeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FD31DD1FEB600811FC7 /* GPUImageXYDerivativeFilter.m */; }; + 843591411DD1FEB600811FC7 /* GPUImageZoomBlurFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FD41DD1FEB600811FC7 /* GPUImageZoomBlurFilter.h */; }; + 843591421DD1FEB600811FC7 /* GPUImageZoomBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FD51DD1FEB600811FC7 /* GPUImageZoomBlurFilter.m */; }; + 843591431DD1FEB600811FC7 /* GPUImageFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FD81DD1FEB600811FC7 /* GPUImageFramework.h */; }; + 843591441DD1FEB600811FC7 /* GPUImageContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FD91DD1FEB600811FC7 /* GPUImageContext.h */; }; + 843591451DD1FEB600811FC7 /* GPUImageContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FDA1DD1FEB600811FC7 /* GPUImageContext.m */; }; + 843591461DD1FEB600811FC7 /* GPUImageMovieWriter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FDB1DD1FEB600811FC7 /* GPUImageMovieWriter.h */; }; + 843591471DD1FEB600811FC7 /* GPUImageMovieWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FDC1DD1FEB600811FC7 /* GPUImageMovieWriter.m */; }; + 843591481DD1FEB600811FC7 /* GPUImagePicture+TextureSubimage.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FDD1DD1FEB600811FC7 /* GPUImagePicture+TextureSubimage.h */; }; + 843591491DD1FEB600811FC7 /* GPUImagePicture+TextureSubimage.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FDE1DD1FEB600811FC7 /* GPUImagePicture+TextureSubimage.m */; }; + 8435914A1DD1FEB600811FC7 /* GPUImagePicture.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FDF1DD1FEB600811FC7 /* GPUImagePicture.h */; }; + 8435914B1DD1FEB600811FC7 /* GPUImagePicture.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FE01DD1FEB600811FC7 /* GPUImagePicture.m */; }; + 8435914C1DD1FEB600811FC7 /* GPUImageView.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FE11DD1FEB600811FC7 /* GPUImageView.h */; }; + 8435914D1DD1FEB600811FC7 /* GPUImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FE21DD1FEB600811FC7 /* GPUImageView.m */; }; + 8435914E1DD1FEB600811FC7 /* amf.c in Sources */ = {isa = PBXBuildFile; fileRef = 84358FE41DD1FEB600811FC7 /* amf.c */; }; + 8435914F1DD1FEB600811FC7 /* amf.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FE51DD1FEB600811FC7 /* amf.h */; }; + 843591501DD1FEB600811FC7 /* bytes.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FE61DD1FEB600811FC7 /* bytes.h */; }; + 843591511DD1FEB600811FC7 /* dh.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FE71DD1FEB600811FC7 /* dh.h */; }; + 843591521DD1FEB600811FC7 /* dhgroups.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FE81DD1FEB600811FC7 /* dhgroups.h */; }; + 843591531DD1FEB600811FC7 /* error.c in Sources */ = {isa = PBXBuildFile; fileRef = 84358FE91DD1FEB600811FC7 /* error.c */; }; + 843591541DD1FEB600811FC7 /* error.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FEA1DD1FEB600811FC7 /* error.h */; }; + 843591551DD1FEB600811FC7 /* handshake.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FEB1DD1FEB600811FC7 /* handshake.h */; }; + 843591561DD1FEB600811FC7 /* hashswf.c in Sources */ = {isa = PBXBuildFile; fileRef = 84358FEC1DD1FEB600811FC7 /* hashswf.c */; }; + 843591571DD1FEB600811FC7 /* http.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FED1DD1FEB600811FC7 /* http.h */; }; + 843591581DD1FEB600811FC7 /* log.c in Sources */ = {isa = PBXBuildFile; fileRef = 84358FEE1DD1FEB600811FC7 /* log.c */; }; + 843591591DD1FEB600811FC7 /* log.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FEF1DD1FEB600811FC7 /* log.h */; }; + 8435915A1DD1FEB600811FC7 /* parseurl.c in Sources */ = {isa = PBXBuildFile; fileRef = 84358FF01DD1FEB600811FC7 /* parseurl.c */; }; + 8435915B1DD1FEB600811FC7 /* rtmp.c in Sources */ = {isa = PBXBuildFile; fileRef = 84358FF11DD1FEB600811FC7 /* rtmp.c */; }; + 8435915C1DD1FEB600811FC7 /* rtmp.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FF21DD1FEB600811FC7 /* rtmp.h */; }; + 8435915D1DD1FEB600811FC7 /* rtmp_sys.h in Headers */ = {isa = PBXBuildFile; fileRef = 84358FF31DD1FEB600811FC7 /* rtmp_sys.h */; }; + 8435916C1DD20A7E00811FC7 /* GLProgram.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E881DD1FEB500811FC7 /* GLProgram.m */; }; + 8435916D1DD20A7E00811FC7 /* GPUImage3x3ConvolutionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E8B1DD1FEB500811FC7 /* GPUImage3x3ConvolutionFilter.m */; }; + 8435916E1DD20A7E00811FC7 /* GPUImage3x3TextureSamplingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E8D1DD1FEB500811FC7 /* GPUImage3x3TextureSamplingFilter.m */; }; + 8435916F1DD20A7E00811FC7 /* GPUImageAdaptiveThresholdFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E8F1DD1FEB500811FC7 /* GPUImageAdaptiveThresholdFilter.m */; }; + 843591701DD20A7E00811FC7 /* GPUImageAddBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E911DD1FEB500811FC7 /* GPUImageAddBlendFilter.m */; }; + 843591711DD20A7E00811FC7 /* GPUImageAlphaBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E931DD1FEB500811FC7 /* GPUImageAlphaBlendFilter.m */; }; + 843591721DD20A7E00811FC7 /* GPUImageAmatorkaFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E951DD1FEB500811FC7 /* GPUImageAmatorkaFilter.m */; }; + 843591731DD20A7E00811FC7 /* GPUImageAverageColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E971DD1FEB500811FC7 /* GPUImageAverageColor.m */; }; + 843591741DD20A7E00811FC7 /* GPUImageAverageLuminanceThresholdFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E991DD1FEB500811FC7 /* GPUImageAverageLuminanceThresholdFilter.m */; }; + 843591751DD20A7E00811FC7 /* GPUImageBilateralFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E9B1DD1FEB500811FC7 /* GPUImageBilateralFilter.m */; }; + 843591761DD20A7E00811FC7 /* GPUImageBoxBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E9D1DD1FEB500811FC7 /* GPUImageBoxBlurFilter.m */; }; + 843591771DD20A7E00811FC7 /* GPUImageBrightnessFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358E9F1DD1FEB500811FC7 /* GPUImageBrightnessFilter.m */; }; + 843591781DD20A7E00811FC7 /* GPUImageBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EA11DD1FEB500811FC7 /* GPUImageBuffer.m */; }; + 843591791DD20A7E00811FC7 /* GPUImageBulgeDistortionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EA31DD1FEB500811FC7 /* GPUImageBulgeDistortionFilter.m */; }; + 8435917A1DD20A7E00811FC7 /* GPUImageCannyEdgeDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EA51DD1FEB500811FC7 /* GPUImageCannyEdgeDetectionFilter.m */; }; + 8435917B1DD20A7E00811FC7 /* GPUImageCGAColorspaceFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EA71DD1FEB500811FC7 /* GPUImageCGAColorspaceFilter.m */; }; + 8435917C1DD20A7E00811FC7 /* GPUImageChromaKeyBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EA91DD1FEB500811FC7 /* GPUImageChromaKeyBlendFilter.m */; }; + 8435917D1DD20A7E00811FC7 /* GPUImageChromaKeyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EAB1DD1FEB500811FC7 /* GPUImageChromaKeyFilter.m */; }; + 8435917E1DD20A7E00811FC7 /* GPUImageClosingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EAD1DD1FEB500811FC7 /* GPUImageClosingFilter.m */; }; + 8435917F1DD20A7E00811FC7 /* GPUImageColorBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EAF1DD1FEB500811FC7 /* GPUImageColorBlendFilter.m */; }; + 843591801DD20A7E00811FC7 /* GPUImageColorBurnBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EB11DD1FEB500811FC7 /* GPUImageColorBurnBlendFilter.m */; }; + 843591811DD20A7E00811FC7 /* GPUImageColorConversion.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EB31DD1FEB500811FC7 /* GPUImageColorConversion.m */; }; + 843591821DD20A7E00811FC7 /* GPUImageColorDodgeBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EB51DD1FEB500811FC7 /* GPUImageColorDodgeBlendFilter.m */; }; + 843591831DD20A7E00811FC7 /* GPUImageColorInvertFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EB71DD1FEB500811FC7 /* GPUImageColorInvertFilter.m */; }; + 843591841DD20A7E00811FC7 /* GPUImageColorLocalBinaryPatternFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EB91DD1FEB500811FC7 /* GPUImageColorLocalBinaryPatternFilter.m */; }; + 843591851DD20A7E00811FC7 /* GPUImageColorMatrixFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EBB1DD1FEB500811FC7 /* GPUImageColorMatrixFilter.m */; }; + 843591861DD20A7E00811FC7 /* GPUImageColorPackingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EBD1DD1FEB500811FC7 /* GPUImageColorPackingFilter.m */; }; + 843591871DD20A7E00811FC7 /* GPUImageColourFASTFeatureDetector.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EBF1DD1FEB500811FC7 /* GPUImageColourFASTFeatureDetector.m */; }; + 843591881DD20A7E00811FC7 /* GPUImageColourFASTSamplingOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EC11DD1FEB500811FC7 /* GPUImageColourFASTSamplingOperation.m */; }; + 843591891DD20A7E00811FC7 /* GPUImageContrastFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EC31DD1FEB500811FC7 /* GPUImageContrastFilter.m */; }; + 8435918A1DD20A7E00811FC7 /* GPUImageCropFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EC51DD1FEB500811FC7 /* GPUImageCropFilter.m */; }; + 8435918B1DD20A7E00811FC7 /* GPUImageCrosshairGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EC71DD1FEB500811FC7 /* GPUImageCrosshairGenerator.m */; }; + 8435918C1DD20A7E00811FC7 /* GPUImageCrosshatchFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EC91DD1FEB500811FC7 /* GPUImageCrosshatchFilter.m */; }; + 8435918D1DD20A7E00811FC7 /* GPUImageDarkenBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ECB1DD1FEB500811FC7 /* GPUImageDarkenBlendFilter.m */; }; + 8435918E1DD20A7E00811FC7 /* GPUImageDifferenceBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ECD1DD1FEB500811FC7 /* GPUImageDifferenceBlendFilter.m */; }; + 8435918F1DD20A7E00811FC7 /* GPUImageDilationFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ECF1DD1FEB500811FC7 /* GPUImageDilationFilter.m */; }; + 843591901DD20A7E00811FC7 /* GPUImageDirectionalNonMaximumSuppressionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ED11DD1FEB500811FC7 /* GPUImageDirectionalNonMaximumSuppressionFilter.m */; }; + 843591911DD20A7E00811FC7 /* GPUImageDirectionalSobelEdgeDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ED31DD1FEB500811FC7 /* GPUImageDirectionalSobelEdgeDetectionFilter.m */; }; + 843591921DD20A7E00811FC7 /* GPUImageDissolveBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ED51DD1FEB500811FC7 /* GPUImageDissolveBlendFilter.m */; }; + 843591931DD20A7E00811FC7 /* GPUImageDivideBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ED71DD1FEB500811FC7 /* GPUImageDivideBlendFilter.m */; }; + 843591941DD20A7E00811FC7 /* GPUImageEmbossFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358ED91DD1FEB500811FC7 /* GPUImageEmbossFilter.m */; }; + 843591951DD20A7E00811FC7 /* GPUImageErosionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EDB1DD1FEB500811FC7 /* GPUImageErosionFilter.m */; }; + 843591961DD20A7E00811FC7 /* GPUImageExclusionBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EDD1DD1FEB500811FC7 /* GPUImageExclusionBlendFilter.m */; }; + 843591971DD20A7E00811FC7 /* GPUImageExposureFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EDF1DD1FEB500811FC7 /* GPUImageExposureFilter.m */; }; + 843591981DD20A7E00811FC7 /* GPUImageFalseColorFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EE11DD1FEB500811FC7 /* GPUImageFalseColorFilter.m */; }; + 843591991DD20A7E00811FC7 /* GPUImageFASTCornerDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EE31DD1FEB500811FC7 /* GPUImageFASTCornerDetectionFilter.m */; }; + 8435919A1DD20A7E00811FC7 /* GPUImageFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EE51DD1FEB500811FC7 /* GPUImageFilter.m */; }; + 8435919B1DD20A7E00811FC7 /* GPUImageFilterGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EE71DD1FEB500811FC7 /* GPUImageFilterGroup.m */; }; + 8435919C1DD20A7E00811FC7 /* GPUImageFilterPipeline.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EE91DD1FEB500811FC7 /* GPUImageFilterPipeline.m */; }; + 8435919D1DD20A7E00811FC7 /* GPUImageFourInputFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EEB1DD1FEB500811FC7 /* GPUImageFourInputFilter.m */; }; + 8435919E1DD20A7E00811FC7 /* GPUImageFramebuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EED1DD1FEB500811FC7 /* GPUImageFramebuffer.m */; }; + 8435919F1DD20A7E00811FC7 /* GPUImageFramebufferCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EEF1DD1FEB500811FC7 /* GPUImageFramebufferCache.m */; }; + 843591A01DD20A7E00811FC7 /* GPUImageGammaFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EF11DD1FEB500811FC7 /* GPUImageGammaFilter.m */; }; + 843591A11DD20A7E00811FC7 /* GPUImageGaussianBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EF31DD1FEB500811FC7 /* GPUImageGaussianBlurFilter.m */; }; + 843591A21DD20A7E00811FC7 /* GPUImageGaussianBlurPositionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EF51DD1FEB500811FC7 /* GPUImageGaussianBlurPositionFilter.m */; }; + 843591A31DD20A7E00811FC7 /* GPUImageGaussianSelectiveBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EF71DD1FEB500811FC7 /* GPUImageGaussianSelectiveBlurFilter.m */; }; + 843591A41DD20A7E00811FC7 /* GPUImageGlassSphereFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EF91DD1FEB500811FC7 /* GPUImageGlassSphereFilter.m */; }; + 843591A51DD20A7E00811FC7 /* GPUImageGrayscaleFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EFB1DD1FEB500811FC7 /* GPUImageGrayscaleFilter.m */; }; + 843591A61DD20A7F00811FC7 /* GPUImageHalftoneFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EFD1DD1FEB500811FC7 /* GPUImageHalftoneFilter.m */; }; + 843591A71DD20A7F00811FC7 /* GPUImageHardLightBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358EFF1DD1FEB500811FC7 /* GPUImageHardLightBlendFilter.m */; }; + 843591A81DD20A7F00811FC7 /* GPUImageHarrisCornerDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F011DD1FEB500811FC7 /* GPUImageHarrisCornerDetectionFilter.m */; }; + 843591A91DD20A7F00811FC7 /* GPUImageHazeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F031DD1FEB500811FC7 /* GPUImageHazeFilter.m */; }; + 843591AA1DD20A7F00811FC7 /* GPUImageHighlightShadowFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F051DD1FEB500811FC7 /* GPUImageHighlightShadowFilter.m */; }; + 843591AB1DD20A7F00811FC7 /* GPUImageHighlightShadowTintFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F071DD1FEB500811FC7 /* GPUImageHighlightShadowTintFilter.m */; }; + 843591AC1DD20A7F00811FC7 /* GPUImageHighPassFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F091DD1FEB500811FC7 /* GPUImageHighPassFilter.m */; }; + 843591AD1DD20A7F00811FC7 /* GPUImageHistogramEqualizationFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F0B1DD1FEB500811FC7 /* GPUImageHistogramEqualizationFilter.m */; }; + 843591AE1DD20A7F00811FC7 /* GPUImageHistogramFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F0D1DD1FEB500811FC7 /* GPUImageHistogramFilter.m */; }; + 843591AF1DD20A7F00811FC7 /* GPUImageHistogramGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F0F1DD1FEB500811FC7 /* GPUImageHistogramGenerator.m */; }; + 843591B01DD20A7F00811FC7 /* GPUImageHoughTransformLineDetector.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F111DD1FEB500811FC7 /* GPUImageHoughTransformLineDetector.m */; }; + 843591B11DD20A7F00811FC7 /* GPUImageHSBFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F131DD1FEB500811FC7 /* GPUImageHSBFilter.m */; }; + 843591B21DD20A7F00811FC7 /* GPUImageHueBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F151DD1FEB500811FC7 /* GPUImageHueBlendFilter.m */; }; + 843591B31DD20A7F00811FC7 /* GPUImageHueFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F171DD1FEB500811FC7 /* GPUImageHueFilter.m */; }; + 843591B41DD20A7F00811FC7 /* GPUImageiOSBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F191DD1FEB500811FC7 /* GPUImageiOSBlurFilter.m */; }; + 843591B51DD20A7F00811FC7 /* GPUImageJFAVoronoiFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F1B1DD1FEB500811FC7 /* GPUImageJFAVoronoiFilter.m */; }; + 843591B61DD20A7F00811FC7 /* GPUImageKuwaharaFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F1D1DD1FEB500811FC7 /* GPUImageKuwaharaFilter.m */; }; + 843591B71DD20A7F00811FC7 /* GPUImageKuwaharaRadius3Filter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F1F1DD1FEB500811FC7 /* GPUImageKuwaharaRadius3Filter.m */; }; + 843591B81DD20A7F00811FC7 /* GPUImageLanczosResamplingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F211DD1FEB500811FC7 /* GPUImageLanczosResamplingFilter.m */; }; + 843591B91DD20A7F00811FC7 /* GPUImageLaplacianFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F231DD1FEB500811FC7 /* GPUImageLaplacianFilter.m */; }; + 843591BA1DD20A7F00811FC7 /* GPUImageLevelsFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F251DD1FEB500811FC7 /* GPUImageLevelsFilter.m */; }; + 843591BB1DD20A7F00811FC7 /* GPUImageLightenBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F271DD1FEB500811FC7 /* GPUImageLightenBlendFilter.m */; }; + 843591BC1DD20A7F00811FC7 /* GPUImageLinearBurnBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F291DD1FEB500811FC7 /* GPUImageLinearBurnBlendFilter.m */; }; + 843591BD1DD20A7F00811FC7 /* GPUImageLineGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F2B1DD1FEB500811FC7 /* GPUImageLineGenerator.m */; }; + 843591BE1DD20A7F00811FC7 /* GPUImageLocalBinaryPatternFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F2D1DD1FEB500811FC7 /* GPUImageLocalBinaryPatternFilter.m */; }; + 843591BF1DD20A7F00811FC7 /* GPUImageLookupFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F2F1DD1FEB500811FC7 /* GPUImageLookupFilter.m */; }; + 843591C01DD20A7F00811FC7 /* GPUImageLowPassFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F311DD1FEB500811FC7 /* GPUImageLowPassFilter.m */; }; + 843591C11DD20A7F00811FC7 /* GPUImageLuminanceRangeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F331DD1FEB500811FC7 /* GPUImageLuminanceRangeFilter.m */; }; + 843591C21DD20A7F00811FC7 /* GPUImageLuminanceThresholdFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F351DD1FEB500811FC7 /* GPUImageLuminanceThresholdFilter.m */; }; + 843591C31DD20A7F00811FC7 /* GPUImageLuminosity.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F371DD1FEB500811FC7 /* GPUImageLuminosity.m */; }; + 843591C41DD20A7F00811FC7 /* GPUImageLuminosityBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F391DD1FEB500811FC7 /* GPUImageLuminosityBlendFilter.m */; }; + 843591C51DD20A7F00811FC7 /* GPUImageMaskFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F3B1DD1FEB500811FC7 /* GPUImageMaskFilter.m */; }; + 843591C61DD20A7F00811FC7 /* GPUImageMedianFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F3D1DD1FEB500811FC7 /* GPUImageMedianFilter.m */; }; + 843591C71DD20A7F00811FC7 /* GPUImageMissEtikateFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F3F1DD1FEB500811FC7 /* GPUImageMissEtikateFilter.m */; }; + 843591C81DD20A7F00811FC7 /* GPUImageMonochromeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F411DD1FEB500811FC7 /* GPUImageMonochromeFilter.m */; }; + 843591C91DD20A7F00811FC7 /* GPUImageMosaicFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F431DD1FEB500811FC7 /* GPUImageMosaicFilter.m */; }; + 843591CA1DD20A7F00811FC7 /* GPUImageMotionBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F451DD1FEB500811FC7 /* GPUImageMotionBlurFilter.m */; }; + 843591CB1DD20A7F00811FC7 /* GPUImageMotionDetector.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F471DD1FEB500811FC7 /* GPUImageMotionDetector.m */; }; + 843591CC1DD20A7F00811FC7 /* GPUImageMovie.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F491DD1FEB500811FC7 /* GPUImageMovie.m */; }; + 843591CD1DD20A7F00811FC7 /* GPUImageMovieComposition.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F4B1DD1FEB500811FC7 /* GPUImageMovieComposition.m */; }; + 843591CE1DD20A7F00811FC7 /* GPUImageMultiplyBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F4D1DD1FEB500811FC7 /* GPUImageMultiplyBlendFilter.m */; }; + 843591CF1DD20A7F00811FC7 /* GPUImageNobleCornerDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F4F1DD1FEB500811FC7 /* GPUImageNobleCornerDetectionFilter.m */; }; + 843591D01DD20A7F00811FC7 /* GPUImageNonMaximumSuppressionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F511DD1FEB500811FC7 /* GPUImageNonMaximumSuppressionFilter.m */; }; + 843591D11DD20A7F00811FC7 /* GPUImageNormalBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F531DD1FEB500811FC7 /* GPUImageNormalBlendFilter.m */; }; + 843591D21DD20A7F00811FC7 /* GPUImageOpacityFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F551DD1FEB500811FC7 /* GPUImageOpacityFilter.m */; }; + 843591D31DD20A7F00811FC7 /* GPUImageOpeningFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F571DD1FEB500811FC7 /* GPUImageOpeningFilter.m */; }; + 843591D41DD20A7F00811FC7 /* GPUImageOutput.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F591DD1FEB500811FC7 /* GPUImageOutput.m */; }; + 843591D51DD20A7F00811FC7 /* GPUImageOverlayBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F5B1DD1FEB500811FC7 /* GPUImageOverlayBlendFilter.m */; }; + 843591D61DD20A7F00811FC7 /* GPUImageParallelCoordinateLineTransformFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F5D1DD1FEB500811FC7 /* GPUImageParallelCoordinateLineTransformFilter.m */; }; + 843591D71DD20A7F00811FC7 /* GPUImagePerlinNoiseFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F5F1DD1FEB500811FC7 /* GPUImagePerlinNoiseFilter.m */; }; + 843591D81DD20A7F00811FC7 /* GPUImagePinchDistortionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F611DD1FEB500811FC7 /* GPUImagePinchDistortionFilter.m */; }; + 843591D91DD20A7F00811FC7 /* GPUImagePixellateFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F631DD1FEB500811FC7 /* GPUImagePixellateFilter.m */; }; + 843591DA1DD20A7F00811FC7 /* GPUImagePixellatePositionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F651DD1FEB500811FC7 /* GPUImagePixellatePositionFilter.m */; }; + 843591DB1DD20A7F00811FC7 /* GPUImagePoissonBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F671DD1FEB500811FC7 /* GPUImagePoissonBlendFilter.m */; }; + 843591DC1DD20A7F00811FC7 /* GPUImagePolarPixellateFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F691DD1FEB500811FC7 /* GPUImagePolarPixellateFilter.m */; }; + 843591DD1DD20A7F00811FC7 /* GPUImagePolkaDotFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F6B1DD1FEB500811FC7 /* GPUImagePolkaDotFilter.m */; }; + 843591DE1DD20A7F00811FC7 /* GPUImagePosterizeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F6D1DD1FEB500811FC7 /* GPUImagePosterizeFilter.m */; }; + 843591DF1DD20A7F00811FC7 /* GPUImagePrewittEdgeDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F6F1DD1FEB500811FC7 /* GPUImagePrewittEdgeDetectionFilter.m */; }; + 843591E01DD20A7F00811FC7 /* GPUImageRawDataInput.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F711DD1FEB500811FC7 /* GPUImageRawDataInput.m */; }; + 843591E11DD20A7F00811FC7 /* GPUImageRawDataOutput.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F731DD1FEB500811FC7 /* GPUImageRawDataOutput.m */; }; + 843591E21DD20A7F00811FC7 /* GPUImageRGBClosingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F751DD1FEB500811FC7 /* GPUImageRGBClosingFilter.m */; }; + 843591E31DD20A7F00811FC7 /* GPUImageRGBDilationFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F771DD1FEB500811FC7 /* GPUImageRGBDilationFilter.m */; }; + 843591E41DD20A7F00811FC7 /* GPUImageRGBErosionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F791DD1FEB500811FC7 /* GPUImageRGBErosionFilter.m */; }; + 843591E51DD20A7F00811FC7 /* GPUImageRGBFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F7B1DD1FEB500811FC7 /* GPUImageRGBFilter.m */; }; + 843591E61DD20A7F00811FC7 /* GPUImageRGBOpeningFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F7D1DD1FEB500811FC7 /* GPUImageRGBOpeningFilter.m */; }; + 843591E71DD20A7F00811FC7 /* GPUImageSaturationBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F7F1DD1FEB500811FC7 /* GPUImageSaturationBlendFilter.m */; }; + 843591E81DD20A7F00811FC7 /* GPUImageSaturationFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F811DD1FEB500811FC7 /* GPUImageSaturationFilter.m */; }; + 843591E91DD20A7F00811FC7 /* GPUImageScreenBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F831DD1FEB500811FC7 /* GPUImageScreenBlendFilter.m */; }; + 843591EA1DD20A7F00811FC7 /* GPUImageSepiaFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F851DD1FEB500811FC7 /* GPUImageSepiaFilter.m */; }; + 843591EB1DD20A7F00811FC7 /* GPUImageSharpenFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F871DD1FEB500811FC7 /* GPUImageSharpenFilter.m */; }; + 843591EC1DD20A7F00811FC7 /* GPUImageShiTomasiFeatureDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F891DD1FEB500811FC7 /* GPUImageShiTomasiFeatureDetectionFilter.m */; }; + 843591ED1DD20A7F00811FC7 /* GPUImageSingleComponentGaussianBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F8B1DD1FEB600811FC7 /* GPUImageSingleComponentGaussianBlurFilter.m */; }; + 843591EE1DD20A7F00811FC7 /* GPUImageSketchFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F8D1DD1FEB600811FC7 /* GPUImageSketchFilter.m */; }; + 843591EF1DD20A7F00811FC7 /* GPUImageSkinToneFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F8F1DD1FEB600811FC7 /* GPUImageSkinToneFilter.m */; }; + 843591F01DD20A7F00811FC7 /* GPUImageSmoothToonFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F911DD1FEB600811FC7 /* GPUImageSmoothToonFilter.m */; }; + 843591F11DD20A7F00811FC7 /* GPUImageSobelEdgeDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F931DD1FEB600811FC7 /* GPUImageSobelEdgeDetectionFilter.m */; }; + 843591F21DD20A7F00811FC7 /* GPUImageSoftEleganceFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F951DD1FEB600811FC7 /* GPUImageSoftEleganceFilter.m */; }; + 843591F31DD20A7F00811FC7 /* GPUImageSoftLightBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F971DD1FEB600811FC7 /* GPUImageSoftLightBlendFilter.m */; }; + 843591F41DD20A7F00811FC7 /* GPUImageSolarizeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F991DD1FEB600811FC7 /* GPUImageSolarizeFilter.m */; }; + 843591F51DD20A7F00811FC7 /* GPUImageSolidColorGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F9B1DD1FEB600811FC7 /* GPUImageSolidColorGenerator.m */; }; + 843591F61DD20A7F00811FC7 /* GPUImageSourceOverBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F9D1DD1FEB600811FC7 /* GPUImageSourceOverBlendFilter.m */; }; + 843591F71DD20A7F00811FC7 /* GPUImageSphereRefractionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358F9F1DD1FEB600811FC7 /* GPUImageSphereRefractionFilter.m */; }; + 843591F81DD20A7F00811FC7 /* GPUImageStillCamera.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FA11DD1FEB600811FC7 /* GPUImageStillCamera.m */; }; + 843591F91DD20A7F00811FC7 /* GPUImageStretchDistortionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FA31DD1FEB600811FC7 /* GPUImageStretchDistortionFilter.m */; }; + 843591FA1DD20A7F00811FC7 /* GPUImageSubtractBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FA51DD1FEB600811FC7 /* GPUImageSubtractBlendFilter.m */; }; + 843591FB1DD20A7F00811FC7 /* GPUImageSwirlFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FA71DD1FEB600811FC7 /* GPUImageSwirlFilter.m */; }; + 843591FC1DD20A7F00811FC7 /* GPUImageTextureInput.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FA91DD1FEB600811FC7 /* GPUImageTextureInput.m */; }; + 843591FD1DD20A7F00811FC7 /* GPUImageTextureOutput.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FAB1DD1FEB600811FC7 /* GPUImageTextureOutput.m */; }; + 843591FE1DD20A7F00811FC7 /* GPUImageThreeInputFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FAD1DD1FEB600811FC7 /* GPUImageThreeInputFilter.m */; }; + 843591FF1DD20A7F00811FC7 /* GPUImageThresholdEdgeDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FAF1DD1FEB600811FC7 /* GPUImageThresholdEdgeDetectionFilter.m */; }; + 843592001DD20A7F00811FC7 /* GPUImageThresholdedNonMaximumSuppressionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FB11DD1FEB600811FC7 /* GPUImageThresholdedNonMaximumSuppressionFilter.m */; }; + 843592011DD20A7F00811FC7 /* GPUImageThresholdSketchFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FB31DD1FEB600811FC7 /* GPUImageThresholdSketchFilter.m */; }; + 843592021DD20A7F00811FC7 /* GPUImageTiltShiftFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FB51DD1FEB600811FC7 /* GPUImageTiltShiftFilter.m */; }; + 843592031DD20A7F00811FC7 /* GPUImageToneCurveFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FB71DD1FEB600811FC7 /* GPUImageToneCurveFilter.m */; }; + 843592041DD20A7F00811FC7 /* GPUImageToonFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FB91DD1FEB600811FC7 /* GPUImageToonFilter.m */; }; + 843592051DD20A7F00811FC7 /* GPUImageTransformFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FBB1DD1FEB600811FC7 /* GPUImageTransformFilter.m */; }; + 843592061DD20A7F00811FC7 /* GPUImageTwoInputCrossTextureSamplingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FBD1DD1FEB600811FC7 /* GPUImageTwoInputCrossTextureSamplingFilter.m */; }; + 843592071DD20A7F00811FC7 /* GPUImageTwoInputFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FBF1DD1FEB600811FC7 /* GPUImageTwoInputFilter.m */; }; + 843592081DD20A7F00811FC7 /* GPUImageTwoPassFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FC11DD1FEB600811FC7 /* GPUImageTwoPassFilter.m */; }; + 843592091DD20A7F00811FC7 /* GPUImageTwoPassTextureSamplingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FC31DD1FEB600811FC7 /* GPUImageTwoPassTextureSamplingFilter.m */; }; + 8435920A1DD20A7F00811FC7 /* GPUImageUIElement.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FC51DD1FEB600811FC7 /* GPUImageUIElement.m */; }; + 8435920B1DD20A7F00811FC7 /* GPUImageUnsharpMaskFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FC71DD1FEB600811FC7 /* GPUImageUnsharpMaskFilter.m */; }; + 8435920C1DD20A7F00811FC7 /* GPUImageVideoCamera.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FC91DD1FEB600811FC7 /* GPUImageVideoCamera.m */; }; + 8435920D1DD20A7F00811FC7 /* GPUImageVignetteFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FCB1DD1FEB600811FC7 /* GPUImageVignetteFilter.m */; }; + 8435920E1DD20A7F00811FC7 /* GPUImageVoronoiConsumerFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FCD1DD1FEB600811FC7 /* GPUImageVoronoiConsumerFilter.m */; }; + 8435920F1DD20A7F00811FC7 /* GPUImageWeakPixelInclusionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FCF1DD1FEB600811FC7 /* GPUImageWeakPixelInclusionFilter.m */; }; + 843592101DD20A7F00811FC7 /* GPUImageWhiteBalanceFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FD11DD1FEB600811FC7 /* GPUImageWhiteBalanceFilter.m */; }; + 843592111DD20A7F00811FC7 /* GPUImageXYDerivativeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FD31DD1FEB600811FC7 /* GPUImageXYDerivativeFilter.m */; }; + 843592121DD20A7F00811FC7 /* GPUImageZoomBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FD51DD1FEB600811FC7 /* GPUImageZoomBlurFilter.m */; }; + 843592131DD20A7F00811FC7 /* GPUImageContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FDA1DD1FEB600811FC7 /* GPUImageContext.m */; }; + 843592141DD20A7F00811FC7 /* GPUImageMovieWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FDC1DD1FEB600811FC7 /* GPUImageMovieWriter.m */; }; + 843592151DD20A7F00811FC7 /* GPUImagePicture+TextureSubimage.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FDE1DD1FEB600811FC7 /* GPUImagePicture+TextureSubimage.m */; }; + 843592161DD20A7F00811FC7 /* GPUImagePicture.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FE01DD1FEB600811FC7 /* GPUImagePicture.m */; }; + 843592171DD20A7F00811FC7 /* GPUImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84358FE21DD1FEB600811FC7 /* GPUImageView.m */; }; + 843592181DD20A9700811FC7 /* amf.c in Sources */ = {isa = PBXBuildFile; fileRef = 84358FE41DD1FEB600811FC7 /* amf.c */; }; + 843592191DD20A9700811FC7 /* error.c in Sources */ = {isa = PBXBuildFile; fileRef = 84358FE91DD1FEB600811FC7 /* error.c */; }; + 8435921A1DD20A9700811FC7 /* hashswf.c in Sources */ = {isa = PBXBuildFile; fileRef = 84358FEC1DD1FEB600811FC7 /* hashswf.c */; }; + 8435921B1DD20A9700811FC7 /* log.c in Sources */ = {isa = PBXBuildFile; fileRef = 84358FEE1DD1FEB600811FC7 /* log.c */; }; + 8435921C1DD20A9700811FC7 /* parseurl.c in Sources */ = {isa = PBXBuildFile; fileRef = 84358FF01DD1FEB600811FC7 /* parseurl.c */; }; + 8435921D1DD20A9700811FC7 /* rtmp.c in Sources */ = {isa = PBXBuildFile; fileRef = 84358FF11DD1FEB600811FC7 /* rtmp.c */; }; + 8495F66F1DB8F14600542124 /* LFLiveKitFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = 8495F66D1DB8F14600542124 /* LFLiveKitFramework.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 8495F6731DB8F1EE00542124 /* LFAudioCapture.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5851D768B6E00752B56 /* LFAudioCapture.h */; }; + 8495F6741DB8F1EE00542124 /* LFVideoCapture.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5871D768B6E00752B56 /* LFVideoCapture.h */; }; + 8495F6751DB8F1EE00542124 /* LFAVEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B58B1D768B6E00752B56 /* LFAVEncoder.h */; }; + 8495F6761DB8F1EE00542124 /* LFMP4Atom.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B58D1D768B6E00752B56 /* LFMP4Atom.h */; }; + 8495F6771DB8F1EE00542124 /* LFNALUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5901D768B6E00752B56 /* LFNALUnit.h */; }; + 8495F6781DB8F1EE00542124 /* LFVideoEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5911D768B6E00752B56 /* LFVideoEncoder.h */; }; + 8495F6791DB8F1EE00542124 /* LFAudioEncoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5931D768B6E00752B56 /* LFAudioEncoding.h */; }; + 8495F67A1DB8F1EE00542124 /* LFH264VideoEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5941D768B6E00752B56 /* LFH264VideoEncoder.h */; }; + 8495F67B1DB8F1EE00542124 /* LFHardwareAudioEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5961D768B6E00752B56 /* LFHardwareAudioEncoder.h */; }; + 8495F67C1DB8F1EE00542124 /* LFHardwareVideoEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5981D768B6E00752B56 /* LFHardwareVideoEncoder.h */; }; + 8495F67D1DB8F1EE00542124 /* LFVideoEncoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B59A1D768B6E00752B56 /* LFVideoEncoding.h */; }; + 8495F67E1DB8F1EE00542124 /* LFLiveAudioConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B59C1D768B6E00752B56 /* LFLiveAudioConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 8495F67F1DB8F1EE00542124 /* LFLiveVideoConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B59E1D768B6E00752B56 /* LFLiveVideoConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 8495F6801DB8F1EE00542124 /* LFGPUImageBeautyFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5A11D768B6E00752B56 /* LFGPUImageBeautyFilter.h */; }; + 8495F6811DB8F1EE00542124 /* LFGPUImageEmptyFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5A31D768B6E00752B56 /* LFGPUImageEmptyFilter.h */; }; + 8495F6831DB8F1EE00542124 /* LFLiveSession.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5A61D768B6E00752B56 /* LFLiveSession.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 8495F6841DB8F1EE00542124 /* LFAudioFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5A91D768B6E00752B56 /* LFAudioFrame.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 8495F6851DB8F1EE00542124 /* LFFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5AB1D768B6E00752B56 /* LFFrame.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 8495F6861DB8F1EE00542124 /* LFLiveDebug.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5AD1D768B6E00752B56 /* LFLiveDebug.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 8495F6871DB8F1EE00542124 /* LFLiveStreamInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5AF1D768B6E00752B56 /* LFLiveStreamInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 8495F6881DB8F1EE00542124 /* LFVideoFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5B11D768B6E00752B56 /* LFVideoFrame.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 8495F6891DB8F1EE00542124 /* LFStreamingBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5B41D768B6E00752B56 /* LFStreamingBuffer.h */; }; + 8495F68A1DB8F1EE00542124 /* LFStreamRTMPSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5B61D768B6E00752B56 /* LFStreamRTMPSocket.h */; }; + 8495F68B1DB8F1EE00542124 /* LFStreamSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5B81D768B6E00752B56 /* LFStreamSocket.h */; }; + 8495F68C1DB8F1EE00542124 /* NSMutableArray+LFAdd.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5B91D768B6E00752B56 /* NSMutableArray+LFAdd.h */; }; + 8495F68D1DB8F27000542124 /* LFAudioCapture.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5861D768B6E00752B56 /* LFAudioCapture.m */; }; + 8495F68E1DB8F27000542124 /* LFVideoCapture.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5881D768B6E00752B56 /* LFVideoCapture.m */; }; + 8495F68F1DB8F27000542124 /* LFAVEncoder.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B58C1D768B6E00752B56 /* LFAVEncoder.mm */; }; + 8495F6901DB8F27000542124 /* LFMP4Atom.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B58E1D768B6E00752B56 /* LFMP4Atom.m */; }; + 8495F6911DB8F27000542124 /* LFVideoEncoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5921D768B6E00752B56 /* LFVideoEncoder.m */; }; + 8495F6921DB8F27000542124 /* LFH264VideoEncoder.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5951D768B6E00752B56 /* LFH264VideoEncoder.mm */; }; + 8495F6931DB8F27000542124 /* LFHardwareAudioEncoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5971D768B6E00752B56 /* LFHardwareAudioEncoder.m */; }; + 8495F6941DB8F27000542124 /* LFHardwareVideoEncoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5991D768B6E00752B56 /* LFHardwareVideoEncoder.m */; }; + 8495F6951DB8F27000542124 /* LFLiveAudioConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B59D1D768B6E00752B56 /* LFLiveAudioConfiguration.m */; }; + 8495F6961DB8F27000542124 /* LFLiveVideoConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B59F1D768B6E00752B56 /* LFLiveVideoConfiguration.m */; }; + 8495F6971DB8F27000542124 /* LFGPUImageBeautyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5A21D768B6E00752B56 /* LFGPUImageBeautyFilter.m */; }; + 8495F6981DB8F27000542124 /* LFGPUImageEmptyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5A41D768B6E00752B56 /* LFGPUImageEmptyFilter.m */; }; + 8495F6991DB8F27000542124 /* LFLiveSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5A71D768B6E00752B56 /* LFLiveSession.m */; }; + 8495F69A1DB8F27000542124 /* LFAudioFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5AA1D768B6E00752B56 /* LFAudioFrame.m */; }; + 8495F69B1DB8F27000542124 /* LFFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5AC1D768B6E00752B56 /* LFFrame.m */; }; + 8495F69C1DB8F27000542124 /* LFLiveDebug.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5AE1D768B6E00752B56 /* LFLiveDebug.m */; }; + 8495F69D1DB8F27000542124 /* LFLiveStreamInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5B01D768B6E00752B56 /* LFLiveStreamInfo.m */; }; + 8495F69E1DB8F27000542124 /* LFVideoFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5B21D768B6E00752B56 /* LFVideoFrame.m */; }; + 8495F69F1DB8F27000542124 /* LFStreamingBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5B51D768B6E00752B56 /* LFStreamingBuffer.m */; }; + 8495F6A01DB8F27000542124 /* LFStreamRtmpSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5B71D768B6E00752B56 /* LFStreamRtmpSocket.m */; }; + 8495F6A11DB8F27000542124 /* NSMutableArray+LFAdd.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5BA1D768B6E00752B56 /* NSMutableArray+LFAdd.m */; }; + 84D0036F1DB8F88F00560583 /* LFNALUnit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B58F1D768B6E00752B56 /* LFNALUnit.cpp */; }; + 84D8B4BF1D757EB800752B56 /* VideoToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D8B4BE1D757EB800752B56 /* VideoToolbox.framework */; }; + 84D8B4C11D757EBE00752B56 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D8B4C01D757EBE00752B56 /* AudioToolbox.framework */; }; + 84D8B4C31D757EC400752B56 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D8B4C21D757EC400752B56 /* AVFoundation.framework */; }; + 84D8B4C51D757EC800752B56 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D8B4C41D757EC800752B56 /* Foundation.framework */; }; + 84D8B4C71D757ECC00752B56 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D8B4C61D757ECC00752B56 /* UIKit.framework */; }; + 84D8B5BB1D768B6E00752B56 /* LFAudioCapture.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5851D768B6E00752B56 /* LFAudioCapture.h */; }; + 84D8B5BC1D768B6E00752B56 /* LFAudioCapture.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5861D768B6E00752B56 /* LFAudioCapture.m */; }; + 84D8B5BD1D768B6E00752B56 /* LFVideoCapture.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5871D768B6E00752B56 /* LFVideoCapture.h */; }; + 84D8B5BE1D768B6E00752B56 /* LFVideoCapture.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5881D768B6E00752B56 /* LFVideoCapture.m */; }; + 84D8B5BF1D768B6E00752B56 /* LFAVEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B58B1D768B6E00752B56 /* LFAVEncoder.h */; }; + 84D8B5C01D768B6E00752B56 /* LFAVEncoder.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B58C1D768B6E00752B56 /* LFAVEncoder.mm */; }; + 84D8B5C11D768B6E00752B56 /* LFMP4Atom.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B58D1D768B6E00752B56 /* LFMP4Atom.h */; }; + 84D8B5C21D768B6E00752B56 /* LFMP4Atom.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B58E1D768B6E00752B56 /* LFMP4Atom.m */; }; + 84D8B5C31D768B6E00752B56 /* LFNALUnit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B58F1D768B6E00752B56 /* LFNALUnit.cpp */; }; + 84D8B5C41D768B6E00752B56 /* LFNALUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5901D768B6E00752B56 /* LFNALUnit.h */; }; + 84D8B5C51D768B6E00752B56 /* LFVideoEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5911D768B6E00752B56 /* LFVideoEncoder.h */; }; + 84D8B5C61D768B6E00752B56 /* LFVideoEncoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5921D768B6E00752B56 /* LFVideoEncoder.m */; }; + 84D8B5C71D768B6E00752B56 /* LFAudioEncoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5931D768B6E00752B56 /* LFAudioEncoding.h */; }; + 84D8B5C81D768B6E00752B56 /* LFH264VideoEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5941D768B6E00752B56 /* LFH264VideoEncoder.h */; }; + 84D8B5C91D768B6E00752B56 /* LFH264VideoEncoder.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5951D768B6E00752B56 /* LFH264VideoEncoder.mm */; }; + 84D8B5CA1D768B6E00752B56 /* LFHardwareAudioEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5961D768B6E00752B56 /* LFHardwareAudioEncoder.h */; }; + 84D8B5CB1D768B6E00752B56 /* LFHardwareAudioEncoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5971D768B6E00752B56 /* LFHardwareAudioEncoder.m */; }; + 84D8B5CC1D768B6E00752B56 /* LFHardwareVideoEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5981D768B6E00752B56 /* LFHardwareVideoEncoder.h */; }; + 84D8B5CD1D768B6E00752B56 /* LFHardwareVideoEncoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5991D768B6E00752B56 /* LFHardwareVideoEncoder.m */; }; + 84D8B5CE1D768B6E00752B56 /* LFVideoEncoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B59A1D768B6E00752B56 /* LFVideoEncoding.h */; }; + 84D8B5CF1D768B6E00752B56 /* LFLiveAudioConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B59C1D768B6E00752B56 /* LFLiveAudioConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84D8B5D01D768B6E00752B56 /* LFLiveAudioConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B59D1D768B6E00752B56 /* LFLiveAudioConfiguration.m */; }; + 84D8B5D11D768B6E00752B56 /* LFLiveVideoConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B59E1D768B6E00752B56 /* LFLiveVideoConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84D8B5D21D768B6E00752B56 /* LFLiveVideoConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B59F1D768B6E00752B56 /* LFLiveVideoConfiguration.m */; }; + 84D8B5D31D768B6E00752B56 /* LFGPUImageBeautyFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5A11D768B6E00752B56 /* LFGPUImageBeautyFilter.h */; }; + 84D8B5D41D768B6E00752B56 /* LFGPUImageBeautyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5A21D768B6E00752B56 /* LFGPUImageBeautyFilter.m */; }; + 84D8B5D51D768B6E00752B56 /* LFGPUImageEmptyFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5A31D768B6E00752B56 /* LFGPUImageEmptyFilter.h */; }; + 84D8B5D61D768B6E00752B56 /* LFGPUImageEmptyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5A41D768B6E00752B56 /* LFGPUImageEmptyFilter.m */; }; + 84D8B5D71D768B6E00752B56 /* LFLiveKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5A51D768B6E00752B56 /* LFLiveKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84D8B5D81D768B6E00752B56 /* LFLiveSession.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5A61D768B6E00752B56 /* LFLiveSession.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84D8B5D91D768B6E00752B56 /* LFLiveSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5A71D768B6E00752B56 /* LFLiveSession.m */; }; + 84D8B5DA1D768B6E00752B56 /* LFAudioFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5A91D768B6E00752B56 /* LFAudioFrame.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84D8B5DB1D768B6E00752B56 /* LFAudioFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5AA1D768B6E00752B56 /* LFAudioFrame.m */; }; + 84D8B5DC1D768B6E00752B56 /* LFFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5AB1D768B6E00752B56 /* LFFrame.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84D8B5DD1D768B6E00752B56 /* LFFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5AC1D768B6E00752B56 /* LFFrame.m */; }; + 84D8B5DE1D768B6E00752B56 /* LFLiveDebug.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5AD1D768B6E00752B56 /* LFLiveDebug.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84D8B5DF1D768B6E00752B56 /* LFLiveDebug.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5AE1D768B6E00752B56 /* LFLiveDebug.m */; }; + 84D8B5E01D768B6E00752B56 /* LFLiveStreamInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5AF1D768B6E00752B56 /* LFLiveStreamInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84D8B5E11D768B6E00752B56 /* LFLiveStreamInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5B01D768B6E00752B56 /* LFLiveStreamInfo.m */; }; + 84D8B5E21D768B6E00752B56 /* LFVideoFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5B11D768B6E00752B56 /* LFVideoFrame.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 84D8B5E31D768B6E00752B56 /* LFVideoFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5B21D768B6E00752B56 /* LFVideoFrame.m */; }; + 84D8B5E41D768B6E00752B56 /* LFStreamingBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5B41D768B6E00752B56 /* LFStreamingBuffer.h */; }; + 84D8B5E51D768B6E00752B56 /* LFStreamingBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5B51D768B6E00752B56 /* LFStreamingBuffer.m */; }; + 84D8B5E61D768B6E00752B56 /* LFStreamRTMPSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5B61D768B6E00752B56 /* LFStreamRTMPSocket.h */; }; + 84D8B5E71D768B6E00752B56 /* LFStreamRtmpSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5B71D768B6E00752B56 /* LFStreamRtmpSocket.m */; }; + 84D8B5E81D768B6E00752B56 /* LFStreamSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5B81D768B6E00752B56 /* LFStreamSocket.h */; }; + 84D8B5E91D768B6E00752B56 /* NSMutableArray+LFAdd.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D8B5B91D768B6E00752B56 /* NSMutableArray+LFAdd.h */; }; + 84D8B5EA1D768B6E00752B56 /* NSMutableArray+LFAdd.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B5BA1D768B6E00752B56 /* NSMutableArray+LFAdd.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 84D003791DB8FE1800560583 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 84D8B3871D7574D600752B56 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 8495F66A1DB8F14600542124; + remoteInfo = LFLiveKitFramework; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 84358E871DD1FEB500811FC7 /* GLProgram.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLProgram.h; sourceTree = ""; }; + 84358E881DD1FEB500811FC7 /* GLProgram.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLProgram.m; sourceTree = ""; }; + 84358E891DD1FEB500811FC7 /* GPUImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImage.h; sourceTree = ""; }; + 84358E8A1DD1FEB500811FC7 /* GPUImage3x3ConvolutionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImage3x3ConvolutionFilter.h; sourceTree = ""; }; + 84358E8B1DD1FEB500811FC7 /* GPUImage3x3ConvolutionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImage3x3ConvolutionFilter.m; sourceTree = ""; }; + 84358E8C1DD1FEB500811FC7 /* GPUImage3x3TextureSamplingFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImage3x3TextureSamplingFilter.h; sourceTree = ""; }; + 84358E8D1DD1FEB500811FC7 /* GPUImage3x3TextureSamplingFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImage3x3TextureSamplingFilter.m; sourceTree = ""; }; + 84358E8E1DD1FEB500811FC7 /* GPUImageAdaptiveThresholdFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageAdaptiveThresholdFilter.h; sourceTree = ""; }; + 84358E8F1DD1FEB500811FC7 /* GPUImageAdaptiveThresholdFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageAdaptiveThresholdFilter.m; sourceTree = ""; }; + 84358E901DD1FEB500811FC7 /* GPUImageAddBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageAddBlendFilter.h; sourceTree = ""; }; + 84358E911DD1FEB500811FC7 /* GPUImageAddBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageAddBlendFilter.m; sourceTree = ""; }; + 84358E921DD1FEB500811FC7 /* GPUImageAlphaBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageAlphaBlendFilter.h; sourceTree = ""; }; + 84358E931DD1FEB500811FC7 /* GPUImageAlphaBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageAlphaBlendFilter.m; sourceTree = ""; }; + 84358E941DD1FEB500811FC7 /* GPUImageAmatorkaFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageAmatorkaFilter.h; sourceTree = ""; }; + 84358E951DD1FEB500811FC7 /* GPUImageAmatorkaFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageAmatorkaFilter.m; sourceTree = ""; }; + 84358E961DD1FEB500811FC7 /* GPUImageAverageColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageAverageColor.h; sourceTree = ""; }; + 84358E971DD1FEB500811FC7 /* GPUImageAverageColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageAverageColor.m; sourceTree = ""; }; + 84358E981DD1FEB500811FC7 /* GPUImageAverageLuminanceThresholdFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageAverageLuminanceThresholdFilter.h; sourceTree = ""; }; + 84358E991DD1FEB500811FC7 /* GPUImageAverageLuminanceThresholdFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageAverageLuminanceThresholdFilter.m; sourceTree = ""; }; + 84358E9A1DD1FEB500811FC7 /* GPUImageBilateralFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageBilateralFilter.h; sourceTree = ""; }; + 84358E9B1DD1FEB500811FC7 /* GPUImageBilateralFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageBilateralFilter.m; sourceTree = ""; }; + 84358E9C1DD1FEB500811FC7 /* GPUImageBoxBlurFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageBoxBlurFilter.h; sourceTree = ""; }; + 84358E9D1DD1FEB500811FC7 /* GPUImageBoxBlurFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageBoxBlurFilter.m; sourceTree = ""; }; + 84358E9E1DD1FEB500811FC7 /* GPUImageBrightnessFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageBrightnessFilter.h; sourceTree = ""; }; + 84358E9F1DD1FEB500811FC7 /* GPUImageBrightnessFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageBrightnessFilter.m; sourceTree = ""; }; + 84358EA01DD1FEB500811FC7 /* GPUImageBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageBuffer.h; sourceTree = ""; }; + 84358EA11DD1FEB500811FC7 /* GPUImageBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageBuffer.m; sourceTree = ""; }; + 84358EA21DD1FEB500811FC7 /* GPUImageBulgeDistortionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageBulgeDistortionFilter.h; sourceTree = ""; }; + 84358EA31DD1FEB500811FC7 /* GPUImageBulgeDistortionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageBulgeDistortionFilter.m; sourceTree = ""; }; + 84358EA41DD1FEB500811FC7 /* GPUImageCannyEdgeDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageCannyEdgeDetectionFilter.h; sourceTree = ""; }; + 84358EA51DD1FEB500811FC7 /* GPUImageCannyEdgeDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageCannyEdgeDetectionFilter.m; sourceTree = ""; }; + 84358EA61DD1FEB500811FC7 /* GPUImageCGAColorspaceFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageCGAColorspaceFilter.h; sourceTree = ""; }; + 84358EA71DD1FEB500811FC7 /* GPUImageCGAColorspaceFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageCGAColorspaceFilter.m; sourceTree = ""; }; + 84358EA81DD1FEB500811FC7 /* GPUImageChromaKeyBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageChromaKeyBlendFilter.h; sourceTree = ""; }; + 84358EA91DD1FEB500811FC7 /* GPUImageChromaKeyBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageChromaKeyBlendFilter.m; sourceTree = ""; }; + 84358EAA1DD1FEB500811FC7 /* GPUImageChromaKeyFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageChromaKeyFilter.h; sourceTree = ""; }; + 84358EAB1DD1FEB500811FC7 /* GPUImageChromaKeyFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageChromaKeyFilter.m; sourceTree = ""; }; + 84358EAC1DD1FEB500811FC7 /* GPUImageClosingFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageClosingFilter.h; sourceTree = ""; }; + 84358EAD1DD1FEB500811FC7 /* GPUImageClosingFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageClosingFilter.m; sourceTree = ""; }; + 84358EAE1DD1FEB500811FC7 /* GPUImageColorBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorBlendFilter.h; sourceTree = ""; }; + 84358EAF1DD1FEB500811FC7 /* GPUImageColorBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorBlendFilter.m; sourceTree = ""; }; + 84358EB01DD1FEB500811FC7 /* GPUImageColorBurnBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorBurnBlendFilter.h; sourceTree = ""; }; + 84358EB11DD1FEB500811FC7 /* GPUImageColorBurnBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorBurnBlendFilter.m; sourceTree = ""; }; + 84358EB21DD1FEB500811FC7 /* GPUImageColorConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorConversion.h; sourceTree = ""; }; + 84358EB31DD1FEB500811FC7 /* GPUImageColorConversion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorConversion.m; sourceTree = ""; }; + 84358EB41DD1FEB500811FC7 /* GPUImageColorDodgeBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorDodgeBlendFilter.h; sourceTree = ""; }; + 84358EB51DD1FEB500811FC7 /* GPUImageColorDodgeBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorDodgeBlendFilter.m; sourceTree = ""; }; + 84358EB61DD1FEB500811FC7 /* GPUImageColorInvertFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorInvertFilter.h; sourceTree = ""; }; + 84358EB71DD1FEB500811FC7 /* GPUImageColorInvertFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorInvertFilter.m; sourceTree = ""; }; + 84358EB81DD1FEB500811FC7 /* GPUImageColorLocalBinaryPatternFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorLocalBinaryPatternFilter.h; sourceTree = ""; }; + 84358EB91DD1FEB500811FC7 /* GPUImageColorLocalBinaryPatternFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorLocalBinaryPatternFilter.m; sourceTree = ""; }; + 84358EBA1DD1FEB500811FC7 /* GPUImageColorMatrixFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorMatrixFilter.h; sourceTree = ""; }; + 84358EBB1DD1FEB500811FC7 /* GPUImageColorMatrixFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorMatrixFilter.m; sourceTree = ""; }; + 84358EBC1DD1FEB500811FC7 /* GPUImageColorPackingFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorPackingFilter.h; sourceTree = ""; }; + 84358EBD1DD1FEB500811FC7 /* GPUImageColorPackingFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorPackingFilter.m; sourceTree = ""; }; + 84358EBE1DD1FEB500811FC7 /* GPUImageColourFASTFeatureDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColourFASTFeatureDetector.h; sourceTree = ""; }; + 84358EBF1DD1FEB500811FC7 /* GPUImageColourFASTFeatureDetector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColourFASTFeatureDetector.m; sourceTree = ""; }; + 84358EC01DD1FEB500811FC7 /* GPUImageColourFASTSamplingOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColourFASTSamplingOperation.h; sourceTree = ""; }; + 84358EC11DD1FEB500811FC7 /* GPUImageColourFASTSamplingOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColourFASTSamplingOperation.m; sourceTree = ""; }; + 84358EC21DD1FEB500811FC7 /* GPUImageContrastFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageContrastFilter.h; sourceTree = ""; }; + 84358EC31DD1FEB500811FC7 /* GPUImageContrastFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageContrastFilter.m; sourceTree = ""; }; + 84358EC41DD1FEB500811FC7 /* GPUImageCropFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageCropFilter.h; sourceTree = ""; }; + 84358EC51DD1FEB500811FC7 /* GPUImageCropFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageCropFilter.m; sourceTree = ""; }; + 84358EC61DD1FEB500811FC7 /* GPUImageCrosshairGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageCrosshairGenerator.h; sourceTree = ""; }; + 84358EC71DD1FEB500811FC7 /* GPUImageCrosshairGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageCrosshairGenerator.m; sourceTree = ""; }; + 84358EC81DD1FEB500811FC7 /* GPUImageCrosshatchFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageCrosshatchFilter.h; sourceTree = ""; }; + 84358EC91DD1FEB500811FC7 /* GPUImageCrosshatchFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageCrosshatchFilter.m; sourceTree = ""; }; + 84358ECA1DD1FEB500811FC7 /* GPUImageDarkenBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageDarkenBlendFilter.h; sourceTree = ""; }; + 84358ECB1DD1FEB500811FC7 /* GPUImageDarkenBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageDarkenBlendFilter.m; sourceTree = ""; }; + 84358ECC1DD1FEB500811FC7 /* GPUImageDifferenceBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageDifferenceBlendFilter.h; sourceTree = ""; }; + 84358ECD1DD1FEB500811FC7 /* GPUImageDifferenceBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageDifferenceBlendFilter.m; sourceTree = ""; }; + 84358ECE1DD1FEB500811FC7 /* GPUImageDilationFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageDilationFilter.h; sourceTree = ""; }; + 84358ECF1DD1FEB500811FC7 /* GPUImageDilationFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageDilationFilter.m; sourceTree = ""; }; + 84358ED01DD1FEB500811FC7 /* GPUImageDirectionalNonMaximumSuppressionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageDirectionalNonMaximumSuppressionFilter.h; sourceTree = ""; }; + 84358ED11DD1FEB500811FC7 /* GPUImageDirectionalNonMaximumSuppressionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageDirectionalNonMaximumSuppressionFilter.m; sourceTree = ""; }; + 84358ED21DD1FEB500811FC7 /* GPUImageDirectionalSobelEdgeDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageDirectionalSobelEdgeDetectionFilter.h; sourceTree = ""; }; + 84358ED31DD1FEB500811FC7 /* GPUImageDirectionalSobelEdgeDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageDirectionalSobelEdgeDetectionFilter.m; sourceTree = ""; }; + 84358ED41DD1FEB500811FC7 /* GPUImageDissolveBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageDissolveBlendFilter.h; sourceTree = ""; }; + 84358ED51DD1FEB500811FC7 /* GPUImageDissolveBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageDissolveBlendFilter.m; sourceTree = ""; }; + 84358ED61DD1FEB500811FC7 /* GPUImageDivideBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageDivideBlendFilter.h; sourceTree = ""; }; + 84358ED71DD1FEB500811FC7 /* GPUImageDivideBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageDivideBlendFilter.m; sourceTree = ""; }; + 84358ED81DD1FEB500811FC7 /* GPUImageEmbossFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageEmbossFilter.h; sourceTree = ""; }; + 84358ED91DD1FEB500811FC7 /* GPUImageEmbossFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageEmbossFilter.m; sourceTree = ""; }; + 84358EDA1DD1FEB500811FC7 /* GPUImageErosionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageErosionFilter.h; sourceTree = ""; }; + 84358EDB1DD1FEB500811FC7 /* GPUImageErosionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageErosionFilter.m; sourceTree = ""; }; + 84358EDC1DD1FEB500811FC7 /* GPUImageExclusionBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageExclusionBlendFilter.h; sourceTree = ""; }; + 84358EDD1DD1FEB500811FC7 /* GPUImageExclusionBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageExclusionBlendFilter.m; sourceTree = ""; }; + 84358EDE1DD1FEB500811FC7 /* GPUImageExposureFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageExposureFilter.h; sourceTree = ""; }; + 84358EDF1DD1FEB500811FC7 /* GPUImageExposureFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageExposureFilter.m; sourceTree = ""; }; + 84358EE01DD1FEB500811FC7 /* GPUImageFalseColorFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFalseColorFilter.h; sourceTree = ""; }; + 84358EE11DD1FEB500811FC7 /* GPUImageFalseColorFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFalseColorFilter.m; sourceTree = ""; }; + 84358EE21DD1FEB500811FC7 /* GPUImageFASTCornerDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFASTCornerDetectionFilter.h; sourceTree = ""; }; + 84358EE31DD1FEB500811FC7 /* GPUImageFASTCornerDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFASTCornerDetectionFilter.m; sourceTree = ""; }; + 84358EE41DD1FEB500811FC7 /* GPUImageFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFilter.h; sourceTree = ""; }; + 84358EE51DD1FEB500811FC7 /* GPUImageFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFilter.m; sourceTree = ""; }; + 84358EE61DD1FEB500811FC7 /* GPUImageFilterGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFilterGroup.h; sourceTree = ""; }; + 84358EE71DD1FEB500811FC7 /* GPUImageFilterGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFilterGroup.m; sourceTree = ""; }; + 84358EE81DD1FEB500811FC7 /* GPUImageFilterPipeline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFilterPipeline.h; sourceTree = ""; }; + 84358EE91DD1FEB500811FC7 /* GPUImageFilterPipeline.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFilterPipeline.m; sourceTree = ""; }; + 84358EEA1DD1FEB500811FC7 /* GPUImageFourInputFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFourInputFilter.h; sourceTree = ""; }; + 84358EEB1DD1FEB500811FC7 /* GPUImageFourInputFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFourInputFilter.m; sourceTree = ""; }; + 84358EEC1DD1FEB500811FC7 /* GPUImageFramebuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFramebuffer.h; sourceTree = ""; }; + 84358EED1DD1FEB500811FC7 /* GPUImageFramebuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFramebuffer.m; sourceTree = ""; }; + 84358EEE1DD1FEB500811FC7 /* GPUImageFramebufferCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFramebufferCache.h; sourceTree = ""; }; + 84358EEF1DD1FEB500811FC7 /* GPUImageFramebufferCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFramebufferCache.m; sourceTree = ""; }; + 84358EF01DD1FEB500811FC7 /* GPUImageGammaFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageGammaFilter.h; sourceTree = ""; }; + 84358EF11DD1FEB500811FC7 /* GPUImageGammaFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageGammaFilter.m; sourceTree = ""; }; + 84358EF21DD1FEB500811FC7 /* GPUImageGaussianBlurFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageGaussianBlurFilter.h; sourceTree = ""; }; + 84358EF31DD1FEB500811FC7 /* GPUImageGaussianBlurFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageGaussianBlurFilter.m; sourceTree = ""; }; + 84358EF41DD1FEB500811FC7 /* GPUImageGaussianBlurPositionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageGaussianBlurPositionFilter.h; sourceTree = ""; }; + 84358EF51DD1FEB500811FC7 /* GPUImageGaussianBlurPositionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageGaussianBlurPositionFilter.m; sourceTree = ""; }; + 84358EF61DD1FEB500811FC7 /* GPUImageGaussianSelectiveBlurFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageGaussianSelectiveBlurFilter.h; sourceTree = ""; }; + 84358EF71DD1FEB500811FC7 /* GPUImageGaussianSelectiveBlurFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageGaussianSelectiveBlurFilter.m; sourceTree = ""; }; + 84358EF81DD1FEB500811FC7 /* GPUImageGlassSphereFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageGlassSphereFilter.h; sourceTree = ""; }; + 84358EF91DD1FEB500811FC7 /* GPUImageGlassSphereFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageGlassSphereFilter.m; sourceTree = ""; }; + 84358EFA1DD1FEB500811FC7 /* GPUImageGrayscaleFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageGrayscaleFilter.h; sourceTree = ""; }; + 84358EFB1DD1FEB500811FC7 /* GPUImageGrayscaleFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageGrayscaleFilter.m; sourceTree = ""; }; + 84358EFC1DD1FEB500811FC7 /* GPUImageHalftoneFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHalftoneFilter.h; sourceTree = ""; }; + 84358EFD1DD1FEB500811FC7 /* GPUImageHalftoneFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHalftoneFilter.m; sourceTree = ""; }; + 84358EFE1DD1FEB500811FC7 /* GPUImageHardLightBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHardLightBlendFilter.h; sourceTree = ""; }; + 84358EFF1DD1FEB500811FC7 /* GPUImageHardLightBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHardLightBlendFilter.m; sourceTree = ""; }; + 84358F001DD1FEB500811FC7 /* GPUImageHarrisCornerDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHarrisCornerDetectionFilter.h; sourceTree = ""; }; + 84358F011DD1FEB500811FC7 /* GPUImageHarrisCornerDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHarrisCornerDetectionFilter.m; sourceTree = ""; }; + 84358F021DD1FEB500811FC7 /* GPUImageHazeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHazeFilter.h; sourceTree = ""; }; + 84358F031DD1FEB500811FC7 /* GPUImageHazeFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHazeFilter.m; sourceTree = ""; }; + 84358F041DD1FEB500811FC7 /* GPUImageHighlightShadowFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHighlightShadowFilter.h; sourceTree = ""; }; + 84358F051DD1FEB500811FC7 /* GPUImageHighlightShadowFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHighlightShadowFilter.m; sourceTree = ""; }; + 84358F061DD1FEB500811FC7 /* GPUImageHighlightShadowTintFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHighlightShadowTintFilter.h; sourceTree = ""; }; + 84358F071DD1FEB500811FC7 /* GPUImageHighlightShadowTintFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHighlightShadowTintFilter.m; sourceTree = ""; }; + 84358F081DD1FEB500811FC7 /* GPUImageHighPassFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHighPassFilter.h; sourceTree = ""; }; + 84358F091DD1FEB500811FC7 /* GPUImageHighPassFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHighPassFilter.m; sourceTree = ""; }; + 84358F0A1DD1FEB500811FC7 /* GPUImageHistogramEqualizationFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHistogramEqualizationFilter.h; sourceTree = ""; }; + 84358F0B1DD1FEB500811FC7 /* GPUImageHistogramEqualizationFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHistogramEqualizationFilter.m; sourceTree = ""; }; + 84358F0C1DD1FEB500811FC7 /* GPUImageHistogramFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHistogramFilter.h; sourceTree = ""; }; + 84358F0D1DD1FEB500811FC7 /* GPUImageHistogramFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHistogramFilter.m; sourceTree = ""; }; + 84358F0E1DD1FEB500811FC7 /* GPUImageHistogramGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHistogramGenerator.h; sourceTree = ""; }; + 84358F0F1DD1FEB500811FC7 /* GPUImageHistogramGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHistogramGenerator.m; sourceTree = ""; }; + 84358F101DD1FEB500811FC7 /* GPUImageHoughTransformLineDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHoughTransformLineDetector.h; sourceTree = ""; }; + 84358F111DD1FEB500811FC7 /* GPUImageHoughTransformLineDetector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHoughTransformLineDetector.m; sourceTree = ""; }; + 84358F121DD1FEB500811FC7 /* GPUImageHSBFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHSBFilter.h; sourceTree = ""; }; + 84358F131DD1FEB500811FC7 /* GPUImageHSBFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHSBFilter.m; sourceTree = ""; }; + 84358F141DD1FEB500811FC7 /* GPUImageHueBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHueBlendFilter.h; sourceTree = ""; }; + 84358F151DD1FEB500811FC7 /* GPUImageHueBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHueBlendFilter.m; sourceTree = ""; }; + 84358F161DD1FEB500811FC7 /* GPUImageHueFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHueFilter.h; sourceTree = ""; }; + 84358F171DD1FEB500811FC7 /* GPUImageHueFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHueFilter.m; sourceTree = ""; }; + 84358F181DD1FEB500811FC7 /* GPUImageiOSBlurFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageiOSBlurFilter.h; sourceTree = ""; }; + 84358F191DD1FEB500811FC7 /* GPUImageiOSBlurFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageiOSBlurFilter.m; sourceTree = ""; }; + 84358F1A1DD1FEB500811FC7 /* GPUImageJFAVoronoiFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageJFAVoronoiFilter.h; sourceTree = ""; }; + 84358F1B1DD1FEB500811FC7 /* GPUImageJFAVoronoiFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageJFAVoronoiFilter.m; sourceTree = ""; }; + 84358F1C1DD1FEB500811FC7 /* GPUImageKuwaharaFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageKuwaharaFilter.h; sourceTree = ""; }; + 84358F1D1DD1FEB500811FC7 /* GPUImageKuwaharaFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageKuwaharaFilter.m; sourceTree = ""; }; + 84358F1E1DD1FEB500811FC7 /* GPUImageKuwaharaRadius3Filter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageKuwaharaRadius3Filter.h; sourceTree = ""; }; + 84358F1F1DD1FEB500811FC7 /* GPUImageKuwaharaRadius3Filter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageKuwaharaRadius3Filter.m; sourceTree = ""; }; + 84358F201DD1FEB500811FC7 /* GPUImageLanczosResamplingFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLanczosResamplingFilter.h; sourceTree = ""; }; + 84358F211DD1FEB500811FC7 /* GPUImageLanczosResamplingFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLanczosResamplingFilter.m; sourceTree = ""; }; + 84358F221DD1FEB500811FC7 /* GPUImageLaplacianFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLaplacianFilter.h; sourceTree = ""; }; + 84358F231DD1FEB500811FC7 /* GPUImageLaplacianFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLaplacianFilter.m; sourceTree = ""; }; + 84358F241DD1FEB500811FC7 /* GPUImageLevelsFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLevelsFilter.h; sourceTree = ""; }; + 84358F251DD1FEB500811FC7 /* GPUImageLevelsFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLevelsFilter.m; sourceTree = ""; }; + 84358F261DD1FEB500811FC7 /* GPUImageLightenBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLightenBlendFilter.h; sourceTree = ""; }; + 84358F271DD1FEB500811FC7 /* GPUImageLightenBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLightenBlendFilter.m; sourceTree = ""; }; + 84358F281DD1FEB500811FC7 /* GPUImageLinearBurnBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLinearBurnBlendFilter.h; sourceTree = ""; }; + 84358F291DD1FEB500811FC7 /* GPUImageLinearBurnBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLinearBurnBlendFilter.m; sourceTree = ""; }; + 84358F2A1DD1FEB500811FC7 /* GPUImageLineGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLineGenerator.h; sourceTree = ""; }; + 84358F2B1DD1FEB500811FC7 /* GPUImageLineGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLineGenerator.m; sourceTree = ""; }; + 84358F2C1DD1FEB500811FC7 /* GPUImageLocalBinaryPatternFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLocalBinaryPatternFilter.h; sourceTree = ""; }; + 84358F2D1DD1FEB500811FC7 /* GPUImageLocalBinaryPatternFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLocalBinaryPatternFilter.m; sourceTree = ""; }; + 84358F2E1DD1FEB500811FC7 /* GPUImageLookupFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLookupFilter.h; sourceTree = ""; }; + 84358F2F1DD1FEB500811FC7 /* GPUImageLookupFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLookupFilter.m; sourceTree = ""; }; + 84358F301DD1FEB500811FC7 /* GPUImageLowPassFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLowPassFilter.h; sourceTree = ""; }; + 84358F311DD1FEB500811FC7 /* GPUImageLowPassFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLowPassFilter.m; sourceTree = ""; }; + 84358F321DD1FEB500811FC7 /* GPUImageLuminanceRangeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLuminanceRangeFilter.h; sourceTree = ""; }; + 84358F331DD1FEB500811FC7 /* GPUImageLuminanceRangeFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLuminanceRangeFilter.m; sourceTree = ""; }; + 84358F341DD1FEB500811FC7 /* GPUImageLuminanceThresholdFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLuminanceThresholdFilter.h; sourceTree = ""; }; + 84358F351DD1FEB500811FC7 /* GPUImageLuminanceThresholdFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLuminanceThresholdFilter.m; sourceTree = ""; }; + 84358F361DD1FEB500811FC7 /* GPUImageLuminosity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLuminosity.h; sourceTree = ""; }; + 84358F371DD1FEB500811FC7 /* GPUImageLuminosity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLuminosity.m; sourceTree = ""; }; + 84358F381DD1FEB500811FC7 /* GPUImageLuminosityBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLuminosityBlendFilter.h; sourceTree = ""; }; + 84358F391DD1FEB500811FC7 /* GPUImageLuminosityBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLuminosityBlendFilter.m; sourceTree = ""; }; + 84358F3A1DD1FEB500811FC7 /* GPUImageMaskFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMaskFilter.h; sourceTree = ""; }; + 84358F3B1DD1FEB500811FC7 /* GPUImageMaskFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMaskFilter.m; sourceTree = ""; }; + 84358F3C1DD1FEB500811FC7 /* GPUImageMedianFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMedianFilter.h; sourceTree = ""; }; + 84358F3D1DD1FEB500811FC7 /* GPUImageMedianFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMedianFilter.m; sourceTree = ""; }; + 84358F3E1DD1FEB500811FC7 /* GPUImageMissEtikateFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMissEtikateFilter.h; sourceTree = ""; }; + 84358F3F1DD1FEB500811FC7 /* GPUImageMissEtikateFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMissEtikateFilter.m; sourceTree = ""; }; + 84358F401DD1FEB500811FC7 /* GPUImageMonochromeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMonochromeFilter.h; sourceTree = ""; }; + 84358F411DD1FEB500811FC7 /* GPUImageMonochromeFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMonochromeFilter.m; sourceTree = ""; }; + 84358F421DD1FEB500811FC7 /* GPUImageMosaicFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMosaicFilter.h; sourceTree = ""; }; + 84358F431DD1FEB500811FC7 /* GPUImageMosaicFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMosaicFilter.m; sourceTree = ""; }; + 84358F441DD1FEB500811FC7 /* GPUImageMotionBlurFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMotionBlurFilter.h; sourceTree = ""; }; + 84358F451DD1FEB500811FC7 /* GPUImageMotionBlurFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMotionBlurFilter.m; sourceTree = ""; }; + 84358F461DD1FEB500811FC7 /* GPUImageMotionDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMotionDetector.h; sourceTree = ""; }; + 84358F471DD1FEB500811FC7 /* GPUImageMotionDetector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMotionDetector.m; sourceTree = ""; }; + 84358F481DD1FEB500811FC7 /* GPUImageMovie.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMovie.h; sourceTree = ""; }; + 84358F491DD1FEB500811FC7 /* GPUImageMovie.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMovie.m; sourceTree = ""; }; + 84358F4A1DD1FEB500811FC7 /* GPUImageMovieComposition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMovieComposition.h; sourceTree = ""; }; + 84358F4B1DD1FEB500811FC7 /* GPUImageMovieComposition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMovieComposition.m; sourceTree = ""; }; + 84358F4C1DD1FEB500811FC7 /* GPUImageMultiplyBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMultiplyBlendFilter.h; sourceTree = ""; }; + 84358F4D1DD1FEB500811FC7 /* GPUImageMultiplyBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMultiplyBlendFilter.m; sourceTree = ""; }; + 84358F4E1DD1FEB500811FC7 /* GPUImageNobleCornerDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageNobleCornerDetectionFilter.h; sourceTree = ""; }; + 84358F4F1DD1FEB500811FC7 /* GPUImageNobleCornerDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageNobleCornerDetectionFilter.m; sourceTree = ""; }; + 84358F501DD1FEB500811FC7 /* GPUImageNonMaximumSuppressionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageNonMaximumSuppressionFilter.h; sourceTree = ""; }; + 84358F511DD1FEB500811FC7 /* GPUImageNonMaximumSuppressionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageNonMaximumSuppressionFilter.m; sourceTree = ""; }; + 84358F521DD1FEB500811FC7 /* GPUImageNormalBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageNormalBlendFilter.h; sourceTree = ""; }; + 84358F531DD1FEB500811FC7 /* GPUImageNormalBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageNormalBlendFilter.m; sourceTree = ""; }; + 84358F541DD1FEB500811FC7 /* GPUImageOpacityFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageOpacityFilter.h; sourceTree = ""; }; + 84358F551DD1FEB500811FC7 /* GPUImageOpacityFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageOpacityFilter.m; sourceTree = ""; }; + 84358F561DD1FEB500811FC7 /* GPUImageOpeningFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageOpeningFilter.h; sourceTree = ""; }; + 84358F571DD1FEB500811FC7 /* GPUImageOpeningFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageOpeningFilter.m; sourceTree = ""; }; + 84358F581DD1FEB500811FC7 /* GPUImageOutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageOutput.h; sourceTree = ""; }; + 84358F591DD1FEB500811FC7 /* GPUImageOutput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageOutput.m; sourceTree = ""; }; + 84358F5A1DD1FEB500811FC7 /* GPUImageOverlayBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageOverlayBlendFilter.h; sourceTree = ""; }; + 84358F5B1DD1FEB500811FC7 /* GPUImageOverlayBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageOverlayBlendFilter.m; sourceTree = ""; }; + 84358F5C1DD1FEB500811FC7 /* GPUImageParallelCoordinateLineTransformFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageParallelCoordinateLineTransformFilter.h; sourceTree = ""; }; + 84358F5D1DD1FEB500811FC7 /* GPUImageParallelCoordinateLineTransformFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageParallelCoordinateLineTransformFilter.m; sourceTree = ""; }; + 84358F5E1DD1FEB500811FC7 /* GPUImagePerlinNoiseFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePerlinNoiseFilter.h; sourceTree = ""; }; + 84358F5F1DD1FEB500811FC7 /* GPUImagePerlinNoiseFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePerlinNoiseFilter.m; sourceTree = ""; }; + 84358F601DD1FEB500811FC7 /* GPUImagePinchDistortionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePinchDistortionFilter.h; sourceTree = ""; }; + 84358F611DD1FEB500811FC7 /* GPUImagePinchDistortionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePinchDistortionFilter.m; sourceTree = ""; }; + 84358F621DD1FEB500811FC7 /* GPUImagePixellateFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePixellateFilter.h; sourceTree = ""; }; + 84358F631DD1FEB500811FC7 /* GPUImagePixellateFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePixellateFilter.m; sourceTree = ""; }; + 84358F641DD1FEB500811FC7 /* GPUImagePixellatePositionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePixellatePositionFilter.h; sourceTree = ""; }; + 84358F651DD1FEB500811FC7 /* GPUImagePixellatePositionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePixellatePositionFilter.m; sourceTree = ""; }; + 84358F661DD1FEB500811FC7 /* GPUImagePoissonBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePoissonBlendFilter.h; sourceTree = ""; }; + 84358F671DD1FEB500811FC7 /* GPUImagePoissonBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePoissonBlendFilter.m; sourceTree = ""; }; + 84358F681DD1FEB500811FC7 /* GPUImagePolarPixellateFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePolarPixellateFilter.h; sourceTree = ""; }; + 84358F691DD1FEB500811FC7 /* GPUImagePolarPixellateFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePolarPixellateFilter.m; sourceTree = ""; }; + 84358F6A1DD1FEB500811FC7 /* GPUImagePolkaDotFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePolkaDotFilter.h; sourceTree = ""; }; + 84358F6B1DD1FEB500811FC7 /* GPUImagePolkaDotFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePolkaDotFilter.m; sourceTree = ""; }; + 84358F6C1DD1FEB500811FC7 /* GPUImagePosterizeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePosterizeFilter.h; sourceTree = ""; }; + 84358F6D1DD1FEB500811FC7 /* GPUImagePosterizeFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePosterizeFilter.m; sourceTree = ""; }; + 84358F6E1DD1FEB500811FC7 /* GPUImagePrewittEdgeDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePrewittEdgeDetectionFilter.h; sourceTree = ""; }; + 84358F6F1DD1FEB500811FC7 /* GPUImagePrewittEdgeDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePrewittEdgeDetectionFilter.m; sourceTree = ""; }; + 84358F701DD1FEB500811FC7 /* GPUImageRawDataInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageRawDataInput.h; sourceTree = ""; }; + 84358F711DD1FEB500811FC7 /* GPUImageRawDataInput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageRawDataInput.m; sourceTree = ""; }; + 84358F721DD1FEB500811FC7 /* GPUImageRawDataOutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageRawDataOutput.h; sourceTree = ""; }; + 84358F731DD1FEB500811FC7 /* GPUImageRawDataOutput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageRawDataOutput.m; sourceTree = ""; }; + 84358F741DD1FEB500811FC7 /* GPUImageRGBClosingFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageRGBClosingFilter.h; sourceTree = ""; }; + 84358F751DD1FEB500811FC7 /* GPUImageRGBClosingFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageRGBClosingFilter.m; sourceTree = ""; }; + 84358F761DD1FEB500811FC7 /* GPUImageRGBDilationFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageRGBDilationFilter.h; sourceTree = ""; }; + 84358F771DD1FEB500811FC7 /* GPUImageRGBDilationFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageRGBDilationFilter.m; sourceTree = ""; }; + 84358F781DD1FEB500811FC7 /* GPUImageRGBErosionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageRGBErosionFilter.h; sourceTree = ""; }; + 84358F791DD1FEB500811FC7 /* GPUImageRGBErosionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageRGBErosionFilter.m; sourceTree = ""; }; + 84358F7A1DD1FEB500811FC7 /* GPUImageRGBFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageRGBFilter.h; sourceTree = ""; }; + 84358F7B1DD1FEB500811FC7 /* GPUImageRGBFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageRGBFilter.m; sourceTree = ""; }; + 84358F7C1DD1FEB500811FC7 /* GPUImageRGBOpeningFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageRGBOpeningFilter.h; sourceTree = ""; }; + 84358F7D1DD1FEB500811FC7 /* GPUImageRGBOpeningFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageRGBOpeningFilter.m; sourceTree = ""; }; + 84358F7E1DD1FEB500811FC7 /* GPUImageSaturationBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSaturationBlendFilter.h; sourceTree = ""; }; + 84358F7F1DD1FEB500811FC7 /* GPUImageSaturationBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSaturationBlendFilter.m; sourceTree = ""; }; + 84358F801DD1FEB500811FC7 /* GPUImageSaturationFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSaturationFilter.h; sourceTree = ""; }; + 84358F811DD1FEB500811FC7 /* GPUImageSaturationFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSaturationFilter.m; sourceTree = ""; }; + 84358F821DD1FEB500811FC7 /* GPUImageScreenBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageScreenBlendFilter.h; sourceTree = ""; }; + 84358F831DD1FEB500811FC7 /* GPUImageScreenBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageScreenBlendFilter.m; sourceTree = ""; }; + 84358F841DD1FEB500811FC7 /* GPUImageSepiaFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSepiaFilter.h; sourceTree = ""; }; + 84358F851DD1FEB500811FC7 /* GPUImageSepiaFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSepiaFilter.m; sourceTree = ""; }; + 84358F861DD1FEB500811FC7 /* GPUImageSharpenFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSharpenFilter.h; sourceTree = ""; }; + 84358F871DD1FEB500811FC7 /* GPUImageSharpenFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSharpenFilter.m; sourceTree = ""; }; + 84358F881DD1FEB500811FC7 /* GPUImageShiTomasiFeatureDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageShiTomasiFeatureDetectionFilter.h; sourceTree = ""; }; + 84358F891DD1FEB500811FC7 /* GPUImageShiTomasiFeatureDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageShiTomasiFeatureDetectionFilter.m; sourceTree = ""; }; + 84358F8A1DD1FEB500811FC7 /* GPUImageSingleComponentGaussianBlurFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSingleComponentGaussianBlurFilter.h; sourceTree = ""; }; + 84358F8B1DD1FEB600811FC7 /* GPUImageSingleComponentGaussianBlurFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSingleComponentGaussianBlurFilter.m; sourceTree = ""; }; + 84358F8C1DD1FEB600811FC7 /* GPUImageSketchFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSketchFilter.h; sourceTree = ""; }; + 84358F8D1DD1FEB600811FC7 /* GPUImageSketchFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSketchFilter.m; sourceTree = ""; }; + 84358F8E1DD1FEB600811FC7 /* GPUImageSkinToneFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSkinToneFilter.h; sourceTree = ""; }; + 84358F8F1DD1FEB600811FC7 /* GPUImageSkinToneFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSkinToneFilter.m; sourceTree = ""; }; + 84358F901DD1FEB600811FC7 /* GPUImageSmoothToonFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSmoothToonFilter.h; sourceTree = ""; }; + 84358F911DD1FEB600811FC7 /* GPUImageSmoothToonFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSmoothToonFilter.m; sourceTree = ""; }; + 84358F921DD1FEB600811FC7 /* GPUImageSobelEdgeDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSobelEdgeDetectionFilter.h; sourceTree = ""; }; + 84358F931DD1FEB600811FC7 /* GPUImageSobelEdgeDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSobelEdgeDetectionFilter.m; sourceTree = ""; }; + 84358F941DD1FEB600811FC7 /* GPUImageSoftEleganceFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSoftEleganceFilter.h; sourceTree = ""; }; + 84358F951DD1FEB600811FC7 /* GPUImageSoftEleganceFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSoftEleganceFilter.m; sourceTree = ""; }; + 84358F961DD1FEB600811FC7 /* GPUImageSoftLightBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSoftLightBlendFilter.h; sourceTree = ""; }; + 84358F971DD1FEB600811FC7 /* GPUImageSoftLightBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSoftLightBlendFilter.m; sourceTree = ""; }; + 84358F981DD1FEB600811FC7 /* GPUImageSolarizeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSolarizeFilter.h; sourceTree = ""; }; + 84358F991DD1FEB600811FC7 /* GPUImageSolarizeFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSolarizeFilter.m; sourceTree = ""; }; + 84358F9A1DD1FEB600811FC7 /* GPUImageSolidColorGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSolidColorGenerator.h; sourceTree = ""; }; + 84358F9B1DD1FEB600811FC7 /* GPUImageSolidColorGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSolidColorGenerator.m; sourceTree = ""; }; + 84358F9C1DD1FEB600811FC7 /* GPUImageSourceOverBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSourceOverBlendFilter.h; sourceTree = ""; }; + 84358F9D1DD1FEB600811FC7 /* GPUImageSourceOverBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSourceOverBlendFilter.m; sourceTree = ""; }; + 84358F9E1DD1FEB600811FC7 /* GPUImageSphereRefractionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSphereRefractionFilter.h; sourceTree = ""; }; + 84358F9F1DD1FEB600811FC7 /* GPUImageSphereRefractionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSphereRefractionFilter.m; sourceTree = ""; }; + 84358FA01DD1FEB600811FC7 /* GPUImageStillCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageStillCamera.h; sourceTree = ""; }; + 84358FA11DD1FEB600811FC7 /* GPUImageStillCamera.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageStillCamera.m; sourceTree = ""; }; + 84358FA21DD1FEB600811FC7 /* GPUImageStretchDistortionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageStretchDistortionFilter.h; sourceTree = ""; }; + 84358FA31DD1FEB600811FC7 /* GPUImageStretchDistortionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageStretchDistortionFilter.m; sourceTree = ""; }; + 84358FA41DD1FEB600811FC7 /* GPUImageSubtractBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSubtractBlendFilter.h; sourceTree = ""; }; + 84358FA51DD1FEB600811FC7 /* GPUImageSubtractBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSubtractBlendFilter.m; sourceTree = ""; }; + 84358FA61DD1FEB600811FC7 /* GPUImageSwirlFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSwirlFilter.h; sourceTree = ""; }; + 84358FA71DD1FEB600811FC7 /* GPUImageSwirlFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSwirlFilter.m; sourceTree = ""; }; + 84358FA81DD1FEB600811FC7 /* GPUImageTextureInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTextureInput.h; sourceTree = ""; }; + 84358FA91DD1FEB600811FC7 /* GPUImageTextureInput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTextureInput.m; sourceTree = ""; }; + 84358FAA1DD1FEB600811FC7 /* GPUImageTextureOutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTextureOutput.h; sourceTree = ""; }; + 84358FAB1DD1FEB600811FC7 /* GPUImageTextureOutput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTextureOutput.m; sourceTree = ""; }; + 84358FAC1DD1FEB600811FC7 /* GPUImageThreeInputFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageThreeInputFilter.h; sourceTree = ""; }; + 84358FAD1DD1FEB600811FC7 /* GPUImageThreeInputFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageThreeInputFilter.m; sourceTree = ""; }; + 84358FAE1DD1FEB600811FC7 /* GPUImageThresholdEdgeDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageThresholdEdgeDetectionFilter.h; sourceTree = ""; }; + 84358FAF1DD1FEB600811FC7 /* GPUImageThresholdEdgeDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageThresholdEdgeDetectionFilter.m; sourceTree = ""; }; + 84358FB01DD1FEB600811FC7 /* GPUImageThresholdedNonMaximumSuppressionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageThresholdedNonMaximumSuppressionFilter.h; sourceTree = ""; }; + 84358FB11DD1FEB600811FC7 /* GPUImageThresholdedNonMaximumSuppressionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageThresholdedNonMaximumSuppressionFilter.m; sourceTree = ""; }; + 84358FB21DD1FEB600811FC7 /* GPUImageThresholdSketchFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageThresholdSketchFilter.h; sourceTree = ""; }; + 84358FB31DD1FEB600811FC7 /* GPUImageThresholdSketchFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageThresholdSketchFilter.m; sourceTree = ""; }; + 84358FB41DD1FEB600811FC7 /* GPUImageTiltShiftFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTiltShiftFilter.h; sourceTree = ""; }; + 84358FB51DD1FEB600811FC7 /* GPUImageTiltShiftFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTiltShiftFilter.m; sourceTree = ""; }; + 84358FB61DD1FEB600811FC7 /* GPUImageToneCurveFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageToneCurveFilter.h; sourceTree = ""; }; + 84358FB71DD1FEB600811FC7 /* GPUImageToneCurveFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageToneCurveFilter.m; sourceTree = ""; }; + 84358FB81DD1FEB600811FC7 /* GPUImageToonFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageToonFilter.h; sourceTree = ""; }; + 84358FB91DD1FEB600811FC7 /* GPUImageToonFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageToonFilter.m; sourceTree = ""; }; + 84358FBA1DD1FEB600811FC7 /* GPUImageTransformFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTransformFilter.h; sourceTree = ""; }; + 84358FBB1DD1FEB600811FC7 /* GPUImageTransformFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTransformFilter.m; sourceTree = ""; }; + 84358FBC1DD1FEB600811FC7 /* GPUImageTwoInputCrossTextureSamplingFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTwoInputCrossTextureSamplingFilter.h; sourceTree = ""; }; + 84358FBD1DD1FEB600811FC7 /* GPUImageTwoInputCrossTextureSamplingFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTwoInputCrossTextureSamplingFilter.m; sourceTree = ""; }; + 84358FBE1DD1FEB600811FC7 /* GPUImageTwoInputFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTwoInputFilter.h; sourceTree = ""; }; + 84358FBF1DD1FEB600811FC7 /* GPUImageTwoInputFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTwoInputFilter.m; sourceTree = ""; }; + 84358FC01DD1FEB600811FC7 /* GPUImageTwoPassFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTwoPassFilter.h; sourceTree = ""; }; + 84358FC11DD1FEB600811FC7 /* GPUImageTwoPassFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTwoPassFilter.m; sourceTree = ""; }; + 84358FC21DD1FEB600811FC7 /* GPUImageTwoPassTextureSamplingFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTwoPassTextureSamplingFilter.h; sourceTree = ""; }; + 84358FC31DD1FEB600811FC7 /* GPUImageTwoPassTextureSamplingFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTwoPassTextureSamplingFilter.m; sourceTree = ""; }; + 84358FC41DD1FEB600811FC7 /* GPUImageUIElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageUIElement.h; sourceTree = ""; }; + 84358FC51DD1FEB600811FC7 /* GPUImageUIElement.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageUIElement.m; sourceTree = ""; }; + 84358FC61DD1FEB600811FC7 /* GPUImageUnsharpMaskFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageUnsharpMaskFilter.h; sourceTree = ""; }; + 84358FC71DD1FEB600811FC7 /* GPUImageUnsharpMaskFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageUnsharpMaskFilter.m; sourceTree = ""; }; + 84358FC81DD1FEB600811FC7 /* GPUImageVideoCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageVideoCamera.h; sourceTree = ""; }; + 84358FC91DD1FEB600811FC7 /* GPUImageVideoCamera.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageVideoCamera.m; sourceTree = ""; }; + 84358FCA1DD1FEB600811FC7 /* GPUImageVignetteFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageVignetteFilter.h; sourceTree = ""; }; + 84358FCB1DD1FEB600811FC7 /* GPUImageVignetteFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageVignetteFilter.m; sourceTree = ""; }; + 84358FCC1DD1FEB600811FC7 /* GPUImageVoronoiConsumerFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageVoronoiConsumerFilter.h; sourceTree = ""; }; + 84358FCD1DD1FEB600811FC7 /* GPUImageVoronoiConsumerFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageVoronoiConsumerFilter.m; sourceTree = ""; }; + 84358FCE1DD1FEB600811FC7 /* GPUImageWeakPixelInclusionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageWeakPixelInclusionFilter.h; sourceTree = ""; }; + 84358FCF1DD1FEB600811FC7 /* GPUImageWeakPixelInclusionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageWeakPixelInclusionFilter.m; sourceTree = ""; }; + 84358FD01DD1FEB600811FC7 /* GPUImageWhiteBalanceFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageWhiteBalanceFilter.h; sourceTree = ""; }; + 84358FD11DD1FEB600811FC7 /* GPUImageWhiteBalanceFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageWhiteBalanceFilter.m; sourceTree = ""; }; + 84358FD21DD1FEB600811FC7 /* GPUImageXYDerivativeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageXYDerivativeFilter.h; sourceTree = ""; }; + 84358FD31DD1FEB600811FC7 /* GPUImageXYDerivativeFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageXYDerivativeFilter.m; sourceTree = ""; }; + 84358FD41DD1FEB600811FC7 /* GPUImageZoomBlurFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageZoomBlurFilter.h; sourceTree = ""; }; + 84358FD51DD1FEB600811FC7 /* GPUImageZoomBlurFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageZoomBlurFilter.m; sourceTree = ""; }; + 84358FD81DD1FEB600811FC7 /* GPUImageFramework.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFramework.h; sourceTree = ""; }; + 84358FD91DD1FEB600811FC7 /* GPUImageContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageContext.h; sourceTree = ""; }; + 84358FDA1DD1FEB600811FC7 /* GPUImageContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageContext.m; sourceTree = ""; }; + 84358FDB1DD1FEB600811FC7 /* GPUImageMovieWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMovieWriter.h; sourceTree = ""; }; + 84358FDC1DD1FEB600811FC7 /* GPUImageMovieWriter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMovieWriter.m; sourceTree = ""; }; + 84358FDD1DD1FEB600811FC7 /* GPUImagePicture+TextureSubimage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GPUImagePicture+TextureSubimage.h"; sourceTree = ""; }; + 84358FDE1DD1FEB600811FC7 /* GPUImagePicture+TextureSubimage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPUImagePicture+TextureSubimage.m"; sourceTree = ""; }; + 84358FDF1DD1FEB600811FC7 /* GPUImagePicture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePicture.h; sourceTree = ""; }; + 84358FE01DD1FEB600811FC7 /* GPUImagePicture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePicture.m; sourceTree = ""; }; + 84358FE11DD1FEB600811FC7 /* GPUImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageView.h; sourceTree = ""; }; + 84358FE21DD1FEB600811FC7 /* GPUImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageView.m; sourceTree = ""; }; + 84358FE41DD1FEB600811FC7 /* amf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = amf.c; sourceTree = ""; }; + 84358FE51DD1FEB600811FC7 /* amf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = amf.h; sourceTree = ""; }; + 84358FE61DD1FEB600811FC7 /* bytes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bytes.h; sourceTree = ""; }; + 84358FE71DD1FEB600811FC7 /* dh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dh.h; sourceTree = ""; }; + 84358FE81DD1FEB600811FC7 /* dhgroups.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dhgroups.h; sourceTree = ""; }; + 84358FE91DD1FEB600811FC7 /* error.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = error.c; sourceTree = ""; }; + 84358FEA1DD1FEB600811FC7 /* error.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = error.h; sourceTree = ""; }; + 84358FEB1DD1FEB600811FC7 /* handshake.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = handshake.h; sourceTree = ""; }; + 84358FEC1DD1FEB600811FC7 /* hashswf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hashswf.c; sourceTree = ""; }; + 84358FED1DD1FEB600811FC7 /* http.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = http.h; sourceTree = ""; }; + 84358FEE1DD1FEB600811FC7 /* log.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = log.c; sourceTree = ""; }; + 84358FEF1DD1FEB600811FC7 /* log.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = log.h; sourceTree = ""; }; + 84358FF01DD1FEB600811FC7 /* parseurl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = parseurl.c; sourceTree = ""; }; + 84358FF11DD1FEB600811FC7 /* rtmp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = rtmp.c; sourceTree = ""; }; + 84358FF21DD1FEB600811FC7 /* rtmp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rtmp.h; sourceTree = ""; }; + 84358FF31DD1FEB600811FC7 /* rtmp_sys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rtmp_sys.h; sourceTree = ""; }; + 8495F66B1DB8F14600542124 /* LFLiveKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LFLiveKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 8495F66D1DB8F14600542124 /* LFLiveKitFramework.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LFLiveKitFramework.h; sourceTree = ""; }; + 8495F66E1DB8F14600542124 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 84D8B3901D7574D600752B56 /* LFLiveKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LFLiveKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 84D8B4BE1D757EB800752B56 /* VideoToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = VideoToolbox.framework; path = System/Library/Frameworks/VideoToolbox.framework; sourceTree = SDKROOT; }; + 84D8B4C01D757EBE00752B56 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; + 84D8B4C21D757EC400752B56 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; + 84D8B4C41D757EC800752B56 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + 84D8B4C61D757ECC00752B56 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + 84D8B4C81D757ED100752B56 /* libstdc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libstdc++.tbd"; path = "usr/lib/libstdc++.tbd"; sourceTree = SDKROOT; }; + 84D8B4CA1D757ED600752B56 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; + 84D8B5851D768B6E00752B56 /* LFAudioCapture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFAudioCapture.h; sourceTree = ""; }; + 84D8B5861D768B6E00752B56 /* LFAudioCapture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFAudioCapture.m; sourceTree = ""; }; + 84D8B5871D768B6E00752B56 /* LFVideoCapture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFVideoCapture.h; sourceTree = ""; }; + 84D8B5881D768B6E00752B56 /* LFVideoCapture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFVideoCapture.m; sourceTree = ""; }; + 84D8B58B1D768B6E00752B56 /* LFAVEncoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFAVEncoder.h; sourceTree = ""; }; + 84D8B58C1D768B6E00752B56 /* LFAVEncoder.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LFAVEncoder.mm; sourceTree = ""; }; + 84D8B58D1D768B6E00752B56 /* LFMP4Atom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFMP4Atom.h; sourceTree = ""; }; + 84D8B58E1D768B6E00752B56 /* LFMP4Atom.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFMP4Atom.m; sourceTree = ""; }; + 84D8B58F1D768B6E00752B56 /* LFNALUnit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LFNALUnit.cpp; sourceTree = ""; }; + 84D8B5901D768B6E00752B56 /* LFNALUnit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFNALUnit.h; sourceTree = ""; }; + 84D8B5911D768B6E00752B56 /* LFVideoEncoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFVideoEncoder.h; sourceTree = ""; }; + 84D8B5921D768B6E00752B56 /* LFVideoEncoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFVideoEncoder.m; sourceTree = ""; }; + 84D8B5931D768B6E00752B56 /* LFAudioEncoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFAudioEncoding.h; sourceTree = ""; }; + 84D8B5941D768B6E00752B56 /* LFH264VideoEncoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFH264VideoEncoder.h; sourceTree = ""; }; + 84D8B5951D768B6E00752B56 /* LFH264VideoEncoder.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LFH264VideoEncoder.mm; sourceTree = ""; }; + 84D8B5961D768B6E00752B56 /* LFHardwareAudioEncoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFHardwareAudioEncoder.h; sourceTree = ""; }; + 84D8B5971D768B6E00752B56 /* LFHardwareAudioEncoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFHardwareAudioEncoder.m; sourceTree = ""; }; + 84D8B5981D768B6E00752B56 /* LFHardwareVideoEncoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFHardwareVideoEncoder.h; sourceTree = ""; }; + 84D8B5991D768B6E00752B56 /* LFHardwareVideoEncoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFHardwareVideoEncoder.m; sourceTree = ""; }; + 84D8B59A1D768B6E00752B56 /* LFVideoEncoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFVideoEncoding.h; sourceTree = ""; }; + 84D8B59C1D768B6E00752B56 /* LFLiveAudioConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFLiveAudioConfiguration.h; sourceTree = ""; }; + 84D8B59D1D768B6E00752B56 /* LFLiveAudioConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFLiveAudioConfiguration.m; sourceTree = ""; }; + 84D8B59E1D768B6E00752B56 /* LFLiveVideoConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFLiveVideoConfiguration.h; sourceTree = ""; }; + 84D8B59F1D768B6E00752B56 /* LFLiveVideoConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFLiveVideoConfiguration.m; sourceTree = ""; }; + 84D8B5A11D768B6E00752B56 /* LFGPUImageBeautyFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFGPUImageBeautyFilter.h; sourceTree = ""; }; + 84D8B5A21D768B6E00752B56 /* LFGPUImageBeautyFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFGPUImageBeautyFilter.m; sourceTree = ""; }; + 84D8B5A31D768B6E00752B56 /* LFGPUImageEmptyFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFGPUImageEmptyFilter.h; sourceTree = ""; }; + 84D8B5A41D768B6E00752B56 /* LFGPUImageEmptyFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFGPUImageEmptyFilter.m; sourceTree = ""; }; + 84D8B5A51D768B6E00752B56 /* LFLiveKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFLiveKit.h; sourceTree = ""; }; + 84D8B5A61D768B6E00752B56 /* LFLiveSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFLiveSession.h; sourceTree = ""; }; + 84D8B5A71D768B6E00752B56 /* LFLiveSession.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFLiveSession.m; sourceTree = ""; }; + 84D8B5A91D768B6E00752B56 /* LFAudioFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFAudioFrame.h; sourceTree = ""; }; + 84D8B5AA1D768B6E00752B56 /* LFAudioFrame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFAudioFrame.m; sourceTree = ""; }; + 84D8B5AB1D768B6E00752B56 /* LFFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFFrame.h; sourceTree = ""; }; + 84D8B5AC1D768B6E00752B56 /* LFFrame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFFrame.m; sourceTree = ""; }; + 84D8B5AD1D768B6E00752B56 /* LFLiveDebug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFLiveDebug.h; sourceTree = ""; }; + 84D8B5AE1D768B6E00752B56 /* LFLiveDebug.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFLiveDebug.m; sourceTree = ""; }; + 84D8B5AF1D768B6E00752B56 /* LFLiveStreamInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFLiveStreamInfo.h; sourceTree = ""; }; + 84D8B5B01D768B6E00752B56 /* LFLiveStreamInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFLiveStreamInfo.m; sourceTree = ""; }; + 84D8B5B11D768B6E00752B56 /* LFVideoFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFVideoFrame.h; sourceTree = ""; }; + 84D8B5B21D768B6E00752B56 /* LFVideoFrame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFVideoFrame.m; sourceTree = ""; }; + 84D8B5B41D768B6E00752B56 /* LFStreamingBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFStreamingBuffer.h; sourceTree = ""; }; + 84D8B5B51D768B6E00752B56 /* LFStreamingBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFStreamingBuffer.m; sourceTree = ""; }; + 84D8B5B61D768B6E00752B56 /* LFStreamRTMPSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFStreamRTMPSocket.h; sourceTree = ""; }; + 84D8B5B71D768B6E00752B56 /* LFStreamRtmpSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFStreamRtmpSocket.m; sourceTree = ""; }; + 84D8B5B81D768B6E00752B56 /* LFStreamSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFStreamSocket.h; sourceTree = ""; }; + 84D8B5B91D768B6E00752B56 /* NSMutableArray+LFAdd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableArray+LFAdd.h"; sourceTree = ""; }; + 84D8B5BA1D768B6E00752B56 /* NSMutableArray+LFAdd.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMutableArray+LFAdd.m"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 8495F6671DB8F14600542124 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 84D8B38C1D7574D600752B56 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 84D8B4C71D757ECC00752B56 /* UIKit.framework in Frameworks */, + 84D8B4C51D757EC800752B56 /* Foundation.framework in Frameworks */, + 84D8B4C31D757EC400752B56 /* AVFoundation.framework in Frameworks */, + 84D8B4C11D757EBE00752B56 /* AudioToolbox.framework in Frameworks */, + 84D8B4BF1D757EB800752B56 /* VideoToolbox.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 84358E851DD1FEB500811FC7 /* Vendor */ = { + isa = PBXGroup; + children = ( + 84358E861DD1FEB500811FC7 /* GPUImage */, + 84358FE31DD1FEB600811FC7 /* pili-librtmp */, + ); + path = Vendor; + sourceTree = ""; + }; + 84358E861DD1FEB500811FC7 /* GPUImage */ = { + isa = PBXGroup; + children = ( + 84358E871DD1FEB500811FC7 /* GLProgram.h */, + 84358E881DD1FEB500811FC7 /* GLProgram.m */, + 84358E891DD1FEB500811FC7 /* GPUImage.h */, + 84358E8A1DD1FEB500811FC7 /* GPUImage3x3ConvolutionFilter.h */, + 84358E8B1DD1FEB500811FC7 /* GPUImage3x3ConvolutionFilter.m */, + 84358E8C1DD1FEB500811FC7 /* GPUImage3x3TextureSamplingFilter.h */, + 84358E8D1DD1FEB500811FC7 /* GPUImage3x3TextureSamplingFilter.m */, + 84358E8E1DD1FEB500811FC7 /* GPUImageAdaptiveThresholdFilter.h */, + 84358E8F1DD1FEB500811FC7 /* GPUImageAdaptiveThresholdFilter.m */, + 84358E901DD1FEB500811FC7 /* GPUImageAddBlendFilter.h */, + 84358E911DD1FEB500811FC7 /* GPUImageAddBlendFilter.m */, + 84358E921DD1FEB500811FC7 /* GPUImageAlphaBlendFilter.h */, + 84358E931DD1FEB500811FC7 /* GPUImageAlphaBlendFilter.m */, + 84358E941DD1FEB500811FC7 /* GPUImageAmatorkaFilter.h */, + 84358E951DD1FEB500811FC7 /* GPUImageAmatorkaFilter.m */, + 84358E961DD1FEB500811FC7 /* GPUImageAverageColor.h */, + 84358E971DD1FEB500811FC7 /* GPUImageAverageColor.m */, + 84358E981DD1FEB500811FC7 /* GPUImageAverageLuminanceThresholdFilter.h */, + 84358E991DD1FEB500811FC7 /* GPUImageAverageLuminanceThresholdFilter.m */, + 84358E9A1DD1FEB500811FC7 /* GPUImageBilateralFilter.h */, + 84358E9B1DD1FEB500811FC7 /* GPUImageBilateralFilter.m */, + 84358E9C1DD1FEB500811FC7 /* GPUImageBoxBlurFilter.h */, + 84358E9D1DD1FEB500811FC7 /* GPUImageBoxBlurFilter.m */, + 84358E9E1DD1FEB500811FC7 /* GPUImageBrightnessFilter.h */, + 84358E9F1DD1FEB500811FC7 /* GPUImageBrightnessFilter.m */, + 84358EA01DD1FEB500811FC7 /* GPUImageBuffer.h */, + 84358EA11DD1FEB500811FC7 /* GPUImageBuffer.m */, + 84358EA21DD1FEB500811FC7 /* GPUImageBulgeDistortionFilter.h */, + 84358EA31DD1FEB500811FC7 /* GPUImageBulgeDistortionFilter.m */, + 84358EA41DD1FEB500811FC7 /* GPUImageCannyEdgeDetectionFilter.h */, + 84358EA51DD1FEB500811FC7 /* GPUImageCannyEdgeDetectionFilter.m */, + 84358EA61DD1FEB500811FC7 /* GPUImageCGAColorspaceFilter.h */, + 84358EA71DD1FEB500811FC7 /* GPUImageCGAColorspaceFilter.m */, + 84358EA81DD1FEB500811FC7 /* GPUImageChromaKeyBlendFilter.h */, + 84358EA91DD1FEB500811FC7 /* GPUImageChromaKeyBlendFilter.m */, + 84358EAA1DD1FEB500811FC7 /* GPUImageChromaKeyFilter.h */, + 84358EAB1DD1FEB500811FC7 /* GPUImageChromaKeyFilter.m */, + 84358EAC1DD1FEB500811FC7 /* GPUImageClosingFilter.h */, + 84358EAD1DD1FEB500811FC7 /* GPUImageClosingFilter.m */, + 84358EAE1DD1FEB500811FC7 /* GPUImageColorBlendFilter.h */, + 84358EAF1DD1FEB500811FC7 /* GPUImageColorBlendFilter.m */, + 84358EB01DD1FEB500811FC7 /* GPUImageColorBurnBlendFilter.h */, + 84358EB11DD1FEB500811FC7 /* GPUImageColorBurnBlendFilter.m */, + 84358EB21DD1FEB500811FC7 /* GPUImageColorConversion.h */, + 84358EB31DD1FEB500811FC7 /* GPUImageColorConversion.m */, + 84358EB41DD1FEB500811FC7 /* GPUImageColorDodgeBlendFilter.h */, + 84358EB51DD1FEB500811FC7 /* GPUImageColorDodgeBlendFilter.m */, + 84358EB61DD1FEB500811FC7 /* GPUImageColorInvertFilter.h */, + 84358EB71DD1FEB500811FC7 /* GPUImageColorInvertFilter.m */, + 84358EB81DD1FEB500811FC7 /* GPUImageColorLocalBinaryPatternFilter.h */, + 84358EB91DD1FEB500811FC7 /* GPUImageColorLocalBinaryPatternFilter.m */, + 84358EBA1DD1FEB500811FC7 /* GPUImageColorMatrixFilter.h */, + 84358EBB1DD1FEB500811FC7 /* GPUImageColorMatrixFilter.m */, + 84358EBC1DD1FEB500811FC7 /* GPUImageColorPackingFilter.h */, + 84358EBD1DD1FEB500811FC7 /* GPUImageColorPackingFilter.m */, + 84358EBE1DD1FEB500811FC7 /* GPUImageColourFASTFeatureDetector.h */, + 84358EBF1DD1FEB500811FC7 /* GPUImageColourFASTFeatureDetector.m */, + 84358EC01DD1FEB500811FC7 /* GPUImageColourFASTSamplingOperation.h */, + 84358EC11DD1FEB500811FC7 /* GPUImageColourFASTSamplingOperation.m */, + 84358EC21DD1FEB500811FC7 /* GPUImageContrastFilter.h */, + 84358EC31DD1FEB500811FC7 /* GPUImageContrastFilter.m */, + 84358EC41DD1FEB500811FC7 /* GPUImageCropFilter.h */, + 84358EC51DD1FEB500811FC7 /* GPUImageCropFilter.m */, + 84358EC61DD1FEB500811FC7 /* GPUImageCrosshairGenerator.h */, + 84358EC71DD1FEB500811FC7 /* GPUImageCrosshairGenerator.m */, + 84358EC81DD1FEB500811FC7 /* GPUImageCrosshatchFilter.h */, + 84358EC91DD1FEB500811FC7 /* GPUImageCrosshatchFilter.m */, + 84358ECA1DD1FEB500811FC7 /* GPUImageDarkenBlendFilter.h */, + 84358ECB1DD1FEB500811FC7 /* GPUImageDarkenBlendFilter.m */, + 84358ECC1DD1FEB500811FC7 /* GPUImageDifferenceBlendFilter.h */, + 84358ECD1DD1FEB500811FC7 /* GPUImageDifferenceBlendFilter.m */, + 84358ECE1DD1FEB500811FC7 /* GPUImageDilationFilter.h */, + 84358ECF1DD1FEB500811FC7 /* GPUImageDilationFilter.m */, + 84358ED01DD1FEB500811FC7 /* GPUImageDirectionalNonMaximumSuppressionFilter.h */, + 84358ED11DD1FEB500811FC7 /* GPUImageDirectionalNonMaximumSuppressionFilter.m */, + 84358ED21DD1FEB500811FC7 /* GPUImageDirectionalSobelEdgeDetectionFilter.h */, + 84358ED31DD1FEB500811FC7 /* GPUImageDirectionalSobelEdgeDetectionFilter.m */, + 84358ED41DD1FEB500811FC7 /* GPUImageDissolveBlendFilter.h */, + 84358ED51DD1FEB500811FC7 /* GPUImageDissolveBlendFilter.m */, + 84358ED61DD1FEB500811FC7 /* GPUImageDivideBlendFilter.h */, + 84358ED71DD1FEB500811FC7 /* GPUImageDivideBlendFilter.m */, + 84358ED81DD1FEB500811FC7 /* GPUImageEmbossFilter.h */, + 84358ED91DD1FEB500811FC7 /* GPUImageEmbossFilter.m */, + 84358EDA1DD1FEB500811FC7 /* GPUImageErosionFilter.h */, + 84358EDB1DD1FEB500811FC7 /* GPUImageErosionFilter.m */, + 84358EDC1DD1FEB500811FC7 /* GPUImageExclusionBlendFilter.h */, + 84358EDD1DD1FEB500811FC7 /* GPUImageExclusionBlendFilter.m */, + 84358EDE1DD1FEB500811FC7 /* GPUImageExposureFilter.h */, + 84358EDF1DD1FEB500811FC7 /* GPUImageExposureFilter.m */, + 84358EE01DD1FEB500811FC7 /* GPUImageFalseColorFilter.h */, + 84358EE11DD1FEB500811FC7 /* GPUImageFalseColorFilter.m */, + 84358EE21DD1FEB500811FC7 /* GPUImageFASTCornerDetectionFilter.h */, + 84358EE31DD1FEB500811FC7 /* GPUImageFASTCornerDetectionFilter.m */, + 84358EE41DD1FEB500811FC7 /* GPUImageFilter.h */, + 84358EE51DD1FEB500811FC7 /* GPUImageFilter.m */, + 84358EE61DD1FEB500811FC7 /* GPUImageFilterGroup.h */, + 84358EE71DD1FEB500811FC7 /* GPUImageFilterGroup.m */, + 84358EE81DD1FEB500811FC7 /* GPUImageFilterPipeline.h */, + 84358EE91DD1FEB500811FC7 /* GPUImageFilterPipeline.m */, + 84358EEA1DD1FEB500811FC7 /* GPUImageFourInputFilter.h */, + 84358EEB1DD1FEB500811FC7 /* GPUImageFourInputFilter.m */, + 84358EEC1DD1FEB500811FC7 /* GPUImageFramebuffer.h */, + 84358EED1DD1FEB500811FC7 /* GPUImageFramebuffer.m */, + 84358EEE1DD1FEB500811FC7 /* GPUImageFramebufferCache.h */, + 84358EEF1DD1FEB500811FC7 /* GPUImageFramebufferCache.m */, + 84358EF01DD1FEB500811FC7 /* GPUImageGammaFilter.h */, + 84358EF11DD1FEB500811FC7 /* GPUImageGammaFilter.m */, + 84358EF21DD1FEB500811FC7 /* GPUImageGaussianBlurFilter.h */, + 84358EF31DD1FEB500811FC7 /* GPUImageGaussianBlurFilter.m */, + 84358EF41DD1FEB500811FC7 /* GPUImageGaussianBlurPositionFilter.h */, + 84358EF51DD1FEB500811FC7 /* GPUImageGaussianBlurPositionFilter.m */, + 84358EF61DD1FEB500811FC7 /* GPUImageGaussianSelectiveBlurFilter.h */, + 84358EF71DD1FEB500811FC7 /* GPUImageGaussianSelectiveBlurFilter.m */, + 84358EF81DD1FEB500811FC7 /* GPUImageGlassSphereFilter.h */, + 84358EF91DD1FEB500811FC7 /* GPUImageGlassSphereFilter.m */, + 84358EFA1DD1FEB500811FC7 /* GPUImageGrayscaleFilter.h */, + 84358EFB1DD1FEB500811FC7 /* GPUImageGrayscaleFilter.m */, + 84358EFC1DD1FEB500811FC7 /* GPUImageHalftoneFilter.h */, + 84358EFD1DD1FEB500811FC7 /* GPUImageHalftoneFilter.m */, + 84358EFE1DD1FEB500811FC7 /* GPUImageHardLightBlendFilter.h */, + 84358EFF1DD1FEB500811FC7 /* GPUImageHardLightBlendFilter.m */, + 84358F001DD1FEB500811FC7 /* GPUImageHarrisCornerDetectionFilter.h */, + 84358F011DD1FEB500811FC7 /* GPUImageHarrisCornerDetectionFilter.m */, + 84358F021DD1FEB500811FC7 /* GPUImageHazeFilter.h */, + 84358F031DD1FEB500811FC7 /* GPUImageHazeFilter.m */, + 84358F041DD1FEB500811FC7 /* GPUImageHighlightShadowFilter.h */, + 84358F051DD1FEB500811FC7 /* GPUImageHighlightShadowFilter.m */, + 84358F061DD1FEB500811FC7 /* GPUImageHighlightShadowTintFilter.h */, + 84358F071DD1FEB500811FC7 /* GPUImageHighlightShadowTintFilter.m */, + 84358F081DD1FEB500811FC7 /* GPUImageHighPassFilter.h */, + 84358F091DD1FEB500811FC7 /* GPUImageHighPassFilter.m */, + 84358F0A1DD1FEB500811FC7 /* GPUImageHistogramEqualizationFilter.h */, + 84358F0B1DD1FEB500811FC7 /* GPUImageHistogramEqualizationFilter.m */, + 84358F0C1DD1FEB500811FC7 /* GPUImageHistogramFilter.h */, + 84358F0D1DD1FEB500811FC7 /* GPUImageHistogramFilter.m */, + 84358F0E1DD1FEB500811FC7 /* GPUImageHistogramGenerator.h */, + 84358F0F1DD1FEB500811FC7 /* GPUImageHistogramGenerator.m */, + 84358F101DD1FEB500811FC7 /* GPUImageHoughTransformLineDetector.h */, + 84358F111DD1FEB500811FC7 /* GPUImageHoughTransformLineDetector.m */, + 84358F121DD1FEB500811FC7 /* GPUImageHSBFilter.h */, + 84358F131DD1FEB500811FC7 /* GPUImageHSBFilter.m */, + 84358F141DD1FEB500811FC7 /* GPUImageHueBlendFilter.h */, + 84358F151DD1FEB500811FC7 /* GPUImageHueBlendFilter.m */, + 84358F161DD1FEB500811FC7 /* GPUImageHueFilter.h */, + 84358F171DD1FEB500811FC7 /* GPUImageHueFilter.m */, + 84358F181DD1FEB500811FC7 /* GPUImageiOSBlurFilter.h */, + 84358F191DD1FEB500811FC7 /* GPUImageiOSBlurFilter.m */, + 84358F1A1DD1FEB500811FC7 /* GPUImageJFAVoronoiFilter.h */, + 84358F1B1DD1FEB500811FC7 /* GPUImageJFAVoronoiFilter.m */, + 84358F1C1DD1FEB500811FC7 /* GPUImageKuwaharaFilter.h */, + 84358F1D1DD1FEB500811FC7 /* GPUImageKuwaharaFilter.m */, + 84358F1E1DD1FEB500811FC7 /* GPUImageKuwaharaRadius3Filter.h */, + 84358F1F1DD1FEB500811FC7 /* GPUImageKuwaharaRadius3Filter.m */, + 84358F201DD1FEB500811FC7 /* GPUImageLanczosResamplingFilter.h */, + 84358F211DD1FEB500811FC7 /* GPUImageLanczosResamplingFilter.m */, + 84358F221DD1FEB500811FC7 /* GPUImageLaplacianFilter.h */, + 84358F231DD1FEB500811FC7 /* GPUImageLaplacianFilter.m */, + 84358F241DD1FEB500811FC7 /* GPUImageLevelsFilter.h */, + 84358F251DD1FEB500811FC7 /* GPUImageLevelsFilter.m */, + 84358F261DD1FEB500811FC7 /* GPUImageLightenBlendFilter.h */, + 84358F271DD1FEB500811FC7 /* GPUImageLightenBlendFilter.m */, + 84358F281DD1FEB500811FC7 /* GPUImageLinearBurnBlendFilter.h */, + 84358F291DD1FEB500811FC7 /* GPUImageLinearBurnBlendFilter.m */, + 84358F2A1DD1FEB500811FC7 /* GPUImageLineGenerator.h */, + 84358F2B1DD1FEB500811FC7 /* GPUImageLineGenerator.m */, + 84358F2C1DD1FEB500811FC7 /* GPUImageLocalBinaryPatternFilter.h */, + 84358F2D1DD1FEB500811FC7 /* GPUImageLocalBinaryPatternFilter.m */, + 84358F2E1DD1FEB500811FC7 /* GPUImageLookupFilter.h */, + 84358F2F1DD1FEB500811FC7 /* GPUImageLookupFilter.m */, + 84358F301DD1FEB500811FC7 /* GPUImageLowPassFilter.h */, + 84358F311DD1FEB500811FC7 /* GPUImageLowPassFilter.m */, + 84358F321DD1FEB500811FC7 /* GPUImageLuminanceRangeFilter.h */, + 84358F331DD1FEB500811FC7 /* GPUImageLuminanceRangeFilter.m */, + 84358F341DD1FEB500811FC7 /* GPUImageLuminanceThresholdFilter.h */, + 84358F351DD1FEB500811FC7 /* GPUImageLuminanceThresholdFilter.m */, + 84358F361DD1FEB500811FC7 /* GPUImageLuminosity.h */, + 84358F371DD1FEB500811FC7 /* GPUImageLuminosity.m */, + 84358F381DD1FEB500811FC7 /* GPUImageLuminosityBlendFilter.h */, + 84358F391DD1FEB500811FC7 /* GPUImageLuminosityBlendFilter.m */, + 84358F3A1DD1FEB500811FC7 /* GPUImageMaskFilter.h */, + 84358F3B1DD1FEB500811FC7 /* GPUImageMaskFilter.m */, + 84358F3C1DD1FEB500811FC7 /* GPUImageMedianFilter.h */, + 84358F3D1DD1FEB500811FC7 /* GPUImageMedianFilter.m */, + 84358F3E1DD1FEB500811FC7 /* GPUImageMissEtikateFilter.h */, + 84358F3F1DD1FEB500811FC7 /* GPUImageMissEtikateFilter.m */, + 84358F401DD1FEB500811FC7 /* GPUImageMonochromeFilter.h */, + 84358F411DD1FEB500811FC7 /* GPUImageMonochromeFilter.m */, + 84358F421DD1FEB500811FC7 /* GPUImageMosaicFilter.h */, + 84358F431DD1FEB500811FC7 /* GPUImageMosaicFilter.m */, + 84358F441DD1FEB500811FC7 /* GPUImageMotionBlurFilter.h */, + 84358F451DD1FEB500811FC7 /* GPUImageMotionBlurFilter.m */, + 84358F461DD1FEB500811FC7 /* GPUImageMotionDetector.h */, + 84358F471DD1FEB500811FC7 /* GPUImageMotionDetector.m */, + 84358F481DD1FEB500811FC7 /* GPUImageMovie.h */, + 84358F491DD1FEB500811FC7 /* GPUImageMovie.m */, + 84358F4A1DD1FEB500811FC7 /* GPUImageMovieComposition.h */, + 84358F4B1DD1FEB500811FC7 /* GPUImageMovieComposition.m */, + 84358F4C1DD1FEB500811FC7 /* GPUImageMultiplyBlendFilter.h */, + 84358F4D1DD1FEB500811FC7 /* GPUImageMultiplyBlendFilter.m */, + 84358F4E1DD1FEB500811FC7 /* GPUImageNobleCornerDetectionFilter.h */, + 84358F4F1DD1FEB500811FC7 /* GPUImageNobleCornerDetectionFilter.m */, + 84358F501DD1FEB500811FC7 /* GPUImageNonMaximumSuppressionFilter.h */, + 84358F511DD1FEB500811FC7 /* GPUImageNonMaximumSuppressionFilter.m */, + 84358F521DD1FEB500811FC7 /* GPUImageNormalBlendFilter.h */, + 84358F531DD1FEB500811FC7 /* GPUImageNormalBlendFilter.m */, + 84358F541DD1FEB500811FC7 /* GPUImageOpacityFilter.h */, + 84358F551DD1FEB500811FC7 /* GPUImageOpacityFilter.m */, + 84358F561DD1FEB500811FC7 /* GPUImageOpeningFilter.h */, + 84358F571DD1FEB500811FC7 /* GPUImageOpeningFilter.m */, + 84358F581DD1FEB500811FC7 /* GPUImageOutput.h */, + 84358F591DD1FEB500811FC7 /* GPUImageOutput.m */, + 84358F5A1DD1FEB500811FC7 /* GPUImageOverlayBlendFilter.h */, + 84358F5B1DD1FEB500811FC7 /* GPUImageOverlayBlendFilter.m */, + 84358F5C1DD1FEB500811FC7 /* GPUImageParallelCoordinateLineTransformFilter.h */, + 84358F5D1DD1FEB500811FC7 /* GPUImageParallelCoordinateLineTransformFilter.m */, + 84358F5E1DD1FEB500811FC7 /* GPUImagePerlinNoiseFilter.h */, + 84358F5F1DD1FEB500811FC7 /* GPUImagePerlinNoiseFilter.m */, + 84358F601DD1FEB500811FC7 /* GPUImagePinchDistortionFilter.h */, + 84358F611DD1FEB500811FC7 /* GPUImagePinchDistortionFilter.m */, + 84358F621DD1FEB500811FC7 /* GPUImagePixellateFilter.h */, + 84358F631DD1FEB500811FC7 /* GPUImagePixellateFilter.m */, + 84358F641DD1FEB500811FC7 /* GPUImagePixellatePositionFilter.h */, + 84358F651DD1FEB500811FC7 /* GPUImagePixellatePositionFilter.m */, + 84358F661DD1FEB500811FC7 /* GPUImagePoissonBlendFilter.h */, + 84358F671DD1FEB500811FC7 /* GPUImagePoissonBlendFilter.m */, + 84358F681DD1FEB500811FC7 /* GPUImagePolarPixellateFilter.h */, + 84358F691DD1FEB500811FC7 /* GPUImagePolarPixellateFilter.m */, + 84358F6A1DD1FEB500811FC7 /* GPUImagePolkaDotFilter.h */, + 84358F6B1DD1FEB500811FC7 /* GPUImagePolkaDotFilter.m */, + 84358F6C1DD1FEB500811FC7 /* GPUImagePosterizeFilter.h */, + 84358F6D1DD1FEB500811FC7 /* GPUImagePosterizeFilter.m */, + 84358F6E1DD1FEB500811FC7 /* GPUImagePrewittEdgeDetectionFilter.h */, + 84358F6F1DD1FEB500811FC7 /* GPUImagePrewittEdgeDetectionFilter.m */, + 84358F701DD1FEB500811FC7 /* GPUImageRawDataInput.h */, + 84358F711DD1FEB500811FC7 /* GPUImageRawDataInput.m */, + 84358F721DD1FEB500811FC7 /* GPUImageRawDataOutput.h */, + 84358F731DD1FEB500811FC7 /* GPUImageRawDataOutput.m */, + 84358F741DD1FEB500811FC7 /* GPUImageRGBClosingFilter.h */, + 84358F751DD1FEB500811FC7 /* GPUImageRGBClosingFilter.m */, + 84358F761DD1FEB500811FC7 /* GPUImageRGBDilationFilter.h */, + 84358F771DD1FEB500811FC7 /* GPUImageRGBDilationFilter.m */, + 84358F781DD1FEB500811FC7 /* GPUImageRGBErosionFilter.h */, + 84358F791DD1FEB500811FC7 /* GPUImageRGBErosionFilter.m */, + 84358F7A1DD1FEB500811FC7 /* GPUImageRGBFilter.h */, + 84358F7B1DD1FEB500811FC7 /* GPUImageRGBFilter.m */, + 84358F7C1DD1FEB500811FC7 /* GPUImageRGBOpeningFilter.h */, + 84358F7D1DD1FEB500811FC7 /* GPUImageRGBOpeningFilter.m */, + 84358F7E1DD1FEB500811FC7 /* GPUImageSaturationBlendFilter.h */, + 84358F7F1DD1FEB500811FC7 /* GPUImageSaturationBlendFilter.m */, + 84358F801DD1FEB500811FC7 /* GPUImageSaturationFilter.h */, + 84358F811DD1FEB500811FC7 /* GPUImageSaturationFilter.m */, + 84358F821DD1FEB500811FC7 /* GPUImageScreenBlendFilter.h */, + 84358F831DD1FEB500811FC7 /* GPUImageScreenBlendFilter.m */, + 84358F841DD1FEB500811FC7 /* GPUImageSepiaFilter.h */, + 84358F851DD1FEB500811FC7 /* GPUImageSepiaFilter.m */, + 84358F861DD1FEB500811FC7 /* GPUImageSharpenFilter.h */, + 84358F871DD1FEB500811FC7 /* GPUImageSharpenFilter.m */, + 84358F881DD1FEB500811FC7 /* GPUImageShiTomasiFeatureDetectionFilter.h */, + 84358F891DD1FEB500811FC7 /* GPUImageShiTomasiFeatureDetectionFilter.m */, + 84358F8A1DD1FEB500811FC7 /* GPUImageSingleComponentGaussianBlurFilter.h */, + 84358F8B1DD1FEB600811FC7 /* GPUImageSingleComponentGaussianBlurFilter.m */, + 84358F8C1DD1FEB600811FC7 /* GPUImageSketchFilter.h */, + 84358F8D1DD1FEB600811FC7 /* GPUImageSketchFilter.m */, + 84358F8E1DD1FEB600811FC7 /* GPUImageSkinToneFilter.h */, + 84358F8F1DD1FEB600811FC7 /* GPUImageSkinToneFilter.m */, + 84358F901DD1FEB600811FC7 /* GPUImageSmoothToonFilter.h */, + 84358F911DD1FEB600811FC7 /* GPUImageSmoothToonFilter.m */, + 84358F921DD1FEB600811FC7 /* GPUImageSobelEdgeDetectionFilter.h */, + 84358F931DD1FEB600811FC7 /* GPUImageSobelEdgeDetectionFilter.m */, + 84358F941DD1FEB600811FC7 /* GPUImageSoftEleganceFilter.h */, + 84358F951DD1FEB600811FC7 /* GPUImageSoftEleganceFilter.m */, + 84358F961DD1FEB600811FC7 /* GPUImageSoftLightBlendFilter.h */, + 84358F971DD1FEB600811FC7 /* GPUImageSoftLightBlendFilter.m */, + 84358F981DD1FEB600811FC7 /* GPUImageSolarizeFilter.h */, + 84358F991DD1FEB600811FC7 /* GPUImageSolarizeFilter.m */, + 84358F9A1DD1FEB600811FC7 /* GPUImageSolidColorGenerator.h */, + 84358F9B1DD1FEB600811FC7 /* GPUImageSolidColorGenerator.m */, + 84358F9C1DD1FEB600811FC7 /* GPUImageSourceOverBlendFilter.h */, + 84358F9D1DD1FEB600811FC7 /* GPUImageSourceOverBlendFilter.m */, + 84358F9E1DD1FEB600811FC7 /* GPUImageSphereRefractionFilter.h */, + 84358F9F1DD1FEB600811FC7 /* GPUImageSphereRefractionFilter.m */, + 84358FA01DD1FEB600811FC7 /* GPUImageStillCamera.h */, + 84358FA11DD1FEB600811FC7 /* GPUImageStillCamera.m */, + 84358FA21DD1FEB600811FC7 /* GPUImageStretchDistortionFilter.h */, + 84358FA31DD1FEB600811FC7 /* GPUImageStretchDistortionFilter.m */, + 84358FA41DD1FEB600811FC7 /* GPUImageSubtractBlendFilter.h */, + 84358FA51DD1FEB600811FC7 /* GPUImageSubtractBlendFilter.m */, + 84358FA61DD1FEB600811FC7 /* GPUImageSwirlFilter.h */, + 84358FA71DD1FEB600811FC7 /* GPUImageSwirlFilter.m */, + 84358FA81DD1FEB600811FC7 /* GPUImageTextureInput.h */, + 84358FA91DD1FEB600811FC7 /* GPUImageTextureInput.m */, + 84358FAA1DD1FEB600811FC7 /* GPUImageTextureOutput.h */, + 84358FAB1DD1FEB600811FC7 /* GPUImageTextureOutput.m */, + 84358FAC1DD1FEB600811FC7 /* GPUImageThreeInputFilter.h */, + 84358FAD1DD1FEB600811FC7 /* GPUImageThreeInputFilter.m */, + 84358FAE1DD1FEB600811FC7 /* GPUImageThresholdEdgeDetectionFilter.h */, + 84358FAF1DD1FEB600811FC7 /* GPUImageThresholdEdgeDetectionFilter.m */, + 84358FB01DD1FEB600811FC7 /* GPUImageThresholdedNonMaximumSuppressionFilter.h */, + 84358FB11DD1FEB600811FC7 /* GPUImageThresholdedNonMaximumSuppressionFilter.m */, + 84358FB21DD1FEB600811FC7 /* GPUImageThresholdSketchFilter.h */, + 84358FB31DD1FEB600811FC7 /* GPUImageThresholdSketchFilter.m */, + 84358FB41DD1FEB600811FC7 /* GPUImageTiltShiftFilter.h */, + 84358FB51DD1FEB600811FC7 /* GPUImageTiltShiftFilter.m */, + 84358FB61DD1FEB600811FC7 /* GPUImageToneCurveFilter.h */, + 84358FB71DD1FEB600811FC7 /* GPUImageToneCurveFilter.m */, + 84358FB81DD1FEB600811FC7 /* GPUImageToonFilter.h */, + 84358FB91DD1FEB600811FC7 /* GPUImageToonFilter.m */, + 84358FBA1DD1FEB600811FC7 /* GPUImageTransformFilter.h */, + 84358FBB1DD1FEB600811FC7 /* GPUImageTransformFilter.m */, + 84358FBC1DD1FEB600811FC7 /* GPUImageTwoInputCrossTextureSamplingFilter.h */, + 84358FBD1DD1FEB600811FC7 /* GPUImageTwoInputCrossTextureSamplingFilter.m */, + 84358FBE1DD1FEB600811FC7 /* GPUImageTwoInputFilter.h */, + 84358FBF1DD1FEB600811FC7 /* GPUImageTwoInputFilter.m */, + 84358FC01DD1FEB600811FC7 /* GPUImageTwoPassFilter.h */, + 84358FC11DD1FEB600811FC7 /* GPUImageTwoPassFilter.m */, + 84358FC21DD1FEB600811FC7 /* GPUImageTwoPassTextureSamplingFilter.h */, + 84358FC31DD1FEB600811FC7 /* GPUImageTwoPassTextureSamplingFilter.m */, + 84358FC41DD1FEB600811FC7 /* GPUImageUIElement.h */, + 84358FC51DD1FEB600811FC7 /* GPUImageUIElement.m */, + 84358FC61DD1FEB600811FC7 /* GPUImageUnsharpMaskFilter.h */, + 84358FC71DD1FEB600811FC7 /* GPUImageUnsharpMaskFilter.m */, + 84358FC81DD1FEB600811FC7 /* GPUImageVideoCamera.h */, + 84358FC91DD1FEB600811FC7 /* GPUImageVideoCamera.m */, + 84358FCA1DD1FEB600811FC7 /* GPUImageVignetteFilter.h */, + 84358FCB1DD1FEB600811FC7 /* GPUImageVignetteFilter.m */, + 84358FCC1DD1FEB600811FC7 /* GPUImageVoronoiConsumerFilter.h */, + 84358FCD1DD1FEB600811FC7 /* GPUImageVoronoiConsumerFilter.m */, + 84358FCE1DD1FEB600811FC7 /* GPUImageWeakPixelInclusionFilter.h */, + 84358FCF1DD1FEB600811FC7 /* GPUImageWeakPixelInclusionFilter.m */, + 84358FD01DD1FEB600811FC7 /* GPUImageWhiteBalanceFilter.h */, + 84358FD11DD1FEB600811FC7 /* GPUImageWhiteBalanceFilter.m */, + 84358FD21DD1FEB600811FC7 /* GPUImageXYDerivativeFilter.h */, + 84358FD31DD1FEB600811FC7 /* GPUImageXYDerivativeFilter.m */, + 84358FD41DD1FEB600811FC7 /* GPUImageZoomBlurFilter.h */, + 84358FD51DD1FEB600811FC7 /* GPUImageZoomBlurFilter.m */, + 84358FD61DD1FEB600811FC7 /* iOS */, + ); + path = GPUImage; + sourceTree = ""; + }; + 84358FD61DD1FEB600811FC7 /* iOS */ = { + isa = PBXGroup; + children = ( + 84358FD71DD1FEB600811FC7 /* Framework */, + 84358FD91DD1FEB600811FC7 /* GPUImageContext.h */, + 84358FDA1DD1FEB600811FC7 /* GPUImageContext.m */, + 84358FDB1DD1FEB600811FC7 /* GPUImageMovieWriter.h */, + 84358FDC1DD1FEB600811FC7 /* GPUImageMovieWriter.m */, + 84358FDD1DD1FEB600811FC7 /* GPUImagePicture+TextureSubimage.h */, + 84358FDE1DD1FEB600811FC7 /* GPUImagePicture+TextureSubimage.m */, + 84358FDF1DD1FEB600811FC7 /* GPUImagePicture.h */, + 84358FE01DD1FEB600811FC7 /* GPUImagePicture.m */, + 84358FE11DD1FEB600811FC7 /* GPUImageView.h */, + 84358FE21DD1FEB600811FC7 /* GPUImageView.m */, + ); + path = iOS; + sourceTree = ""; + }; + 84358FD71DD1FEB600811FC7 /* Framework */ = { + isa = PBXGroup; + children = ( + 84358FD81DD1FEB600811FC7 /* GPUImageFramework.h */, + ); + path = Framework; + sourceTree = ""; + }; + 84358FE31DD1FEB600811FC7 /* pili-librtmp */ = { + isa = PBXGroup; + children = ( + 84358FE41DD1FEB600811FC7 /* amf.c */, + 84358FE51DD1FEB600811FC7 /* amf.h */, + 84358FE61DD1FEB600811FC7 /* bytes.h */, + 84358FE71DD1FEB600811FC7 /* dh.h */, + 84358FE81DD1FEB600811FC7 /* dhgroups.h */, + 84358FE91DD1FEB600811FC7 /* error.c */, + 84358FEA1DD1FEB600811FC7 /* error.h */, + 84358FEB1DD1FEB600811FC7 /* handshake.h */, + 84358FEC1DD1FEB600811FC7 /* hashswf.c */, + 84358FED1DD1FEB600811FC7 /* http.h */, + 84358FEE1DD1FEB600811FC7 /* log.c */, + 84358FEF1DD1FEB600811FC7 /* log.h */, + 84358FF01DD1FEB600811FC7 /* parseurl.c */, + 84358FF11DD1FEB600811FC7 /* rtmp.c */, + 84358FF21DD1FEB600811FC7 /* rtmp.h */, + 84358FF31DD1FEB600811FC7 /* rtmp_sys.h */, + ); + path = "pili-librtmp"; + sourceTree = ""; + }; + 8495F66C1DB8F14600542124 /* LFLiveKitFramework */ = { + isa = PBXGroup; + children = ( + 8495F66D1DB8F14600542124 /* LFLiveKitFramework.h */, + 8495F66E1DB8F14600542124 /* Info.plist */, + ); + path = LFLiveKitFramework; + sourceTree = ""; + }; + 84D8B3861D7574D600752B56 = { + isa = PBXGroup; + children = ( + 84D8B5831D768B6E00752B56 /* LFLiveKit */, + 84D8B4CA1D757ED600752B56 /* libz.tbd */, + 84D8B4C81D757ED100752B56 /* libstdc++.tbd */, + 84D8B4C61D757ECC00752B56 /* UIKit.framework */, + 84D8B4C41D757EC800752B56 /* Foundation.framework */, + 84D8B4C21D757EC400752B56 /* AVFoundation.framework */, + 84D8B4C01D757EBE00752B56 /* AudioToolbox.framework */, + 84D8B4BE1D757EB800752B56 /* VideoToolbox.framework */, + 8495F66C1DB8F14600542124 /* LFLiveKitFramework */, + 84D8B3911D7574D600752B56 /* Products */, + 9ABACAFFC334034AA0115426 /* Frameworks */, + ); + sourceTree = ""; + }; + 84D8B3911D7574D600752B56 /* Products */ = { + isa = PBXGroup; + children = ( + 84D8B3901D7574D600752B56 /* LFLiveKit.framework */, + 8495F66B1DB8F14600542124 /* LFLiveKit.framework */, + ); + name = Products; + sourceTree = ""; + }; + 84D8B5831D768B6E00752B56 /* LFLiveKit */ = { + isa = PBXGroup; + children = ( + 84D8B5841D768B6E00752B56 /* capture */, + 84D8B5891D768B6E00752B56 /* coder */, + 84D8B59B1D768B6E00752B56 /* configuration */, + 84D8B5A01D768B6E00752B56 /* filter */, + 84D8B5A51D768B6E00752B56 /* LFLiveKit.h */, + 84D8B5A61D768B6E00752B56 /* LFLiveSession.h */, + 84D8B5A71D768B6E00752B56 /* LFLiveSession.m */, + 84D8B5A81D768B6E00752B56 /* objects */, + 84D8B5B31D768B6E00752B56 /* publish */, + 84358E851DD1FEB500811FC7 /* Vendor */, + ); + name = LFLiveKit; + path = ../LFLiveKit; + sourceTree = ""; + }; + 84D8B5841D768B6E00752B56 /* capture */ = { + isa = PBXGroup; + children = ( + 84D8B5851D768B6E00752B56 /* LFAudioCapture.h */, + 84D8B5861D768B6E00752B56 /* LFAudioCapture.m */, + 84D8B5871D768B6E00752B56 /* LFVideoCapture.h */, + 84D8B5881D768B6E00752B56 /* LFVideoCapture.m */, + ); + path = capture; + sourceTree = ""; + }; + 84D8B5891D768B6E00752B56 /* coder */ = { + isa = PBXGroup; + children = ( + 84D8B58A1D768B6E00752B56 /* H264 */, + 84D8B5931D768B6E00752B56 /* LFAudioEncoding.h */, + 84D8B5941D768B6E00752B56 /* LFH264VideoEncoder.h */, + 84D8B5951D768B6E00752B56 /* LFH264VideoEncoder.mm */, + 84D8B5961D768B6E00752B56 /* LFHardwareAudioEncoder.h */, + 84D8B5971D768B6E00752B56 /* LFHardwareAudioEncoder.m */, + 84D8B5981D768B6E00752B56 /* LFHardwareVideoEncoder.h */, + 84D8B5991D768B6E00752B56 /* LFHardwareVideoEncoder.m */, + 84D8B59A1D768B6E00752B56 /* LFVideoEncoding.h */, + ); + path = coder; + sourceTree = ""; + }; + 84D8B58A1D768B6E00752B56 /* H264 */ = { + isa = PBXGroup; + children = ( + 84D8B58B1D768B6E00752B56 /* LFAVEncoder.h */, + 84D8B58C1D768B6E00752B56 /* LFAVEncoder.mm */, + 84D8B58D1D768B6E00752B56 /* LFMP4Atom.h */, + 84D8B58E1D768B6E00752B56 /* LFMP4Atom.m */, + 84D8B58F1D768B6E00752B56 /* LFNALUnit.cpp */, + 84D8B5901D768B6E00752B56 /* LFNALUnit.h */, + 84D8B5911D768B6E00752B56 /* LFVideoEncoder.h */, + 84D8B5921D768B6E00752B56 /* LFVideoEncoder.m */, + ); + path = H264; + sourceTree = ""; + }; + 84D8B59B1D768B6E00752B56 /* configuration */ = { + isa = PBXGroup; + children = ( + 84D8B59C1D768B6E00752B56 /* LFLiveAudioConfiguration.h */, + 84D8B59D1D768B6E00752B56 /* LFLiveAudioConfiguration.m */, + 84D8B59E1D768B6E00752B56 /* LFLiveVideoConfiguration.h */, + 84D8B59F1D768B6E00752B56 /* LFLiveVideoConfiguration.m */, + ); + path = configuration; + sourceTree = ""; + }; + 84D8B5A01D768B6E00752B56 /* filter */ = { + isa = PBXGroup; + children = ( + 84D8B5A11D768B6E00752B56 /* LFGPUImageBeautyFilter.h */, + 84D8B5A21D768B6E00752B56 /* LFGPUImageBeautyFilter.m */, + 84D8B5A31D768B6E00752B56 /* LFGPUImageEmptyFilter.h */, + 84D8B5A41D768B6E00752B56 /* LFGPUImageEmptyFilter.m */, + ); + path = filter; + sourceTree = ""; + }; + 84D8B5A81D768B6E00752B56 /* objects */ = { + isa = PBXGroup; + children = ( + 84D8B5A91D768B6E00752B56 /* LFAudioFrame.h */, + 84D8B5AA1D768B6E00752B56 /* LFAudioFrame.m */, + 84D8B5AB1D768B6E00752B56 /* LFFrame.h */, + 84D8B5AC1D768B6E00752B56 /* LFFrame.m */, + 84D8B5AD1D768B6E00752B56 /* LFLiveDebug.h */, + 84D8B5AE1D768B6E00752B56 /* LFLiveDebug.m */, + 84D8B5AF1D768B6E00752B56 /* LFLiveStreamInfo.h */, + 84D8B5B01D768B6E00752B56 /* LFLiveStreamInfo.m */, + 84D8B5B11D768B6E00752B56 /* LFVideoFrame.h */, + 84D8B5B21D768B6E00752B56 /* LFVideoFrame.m */, + ); + path = objects; + sourceTree = ""; + }; + 84D8B5B31D768B6E00752B56 /* publish */ = { + isa = PBXGroup; + children = ( + 84D8B5B41D768B6E00752B56 /* LFStreamingBuffer.h */, + 84D8B5B51D768B6E00752B56 /* LFStreamingBuffer.m */, + 84D8B5B61D768B6E00752B56 /* LFStreamRTMPSocket.h */, + 84D8B5B71D768B6E00752B56 /* LFStreamRtmpSocket.m */, + 84D8B5B81D768B6E00752B56 /* LFStreamSocket.h */, + 84D8B5B91D768B6E00752B56 /* NSMutableArray+LFAdd.h */, + 84D8B5BA1D768B6E00752B56 /* NSMutableArray+LFAdd.m */, + ); + path = publish; + sourceTree = ""; + }; + 9ABACAFFC334034AA0115426 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 8495F6681DB8F14600542124 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 8495F6861DB8F1EE00542124 /* LFLiveDebug.h in Headers */, + 8495F6881DB8F1EE00542124 /* LFVideoFrame.h in Headers */, + 8495F6871DB8F1EE00542124 /* LFLiveStreamInfo.h in Headers */, + 8495F6851DB8F1EE00542124 /* LFFrame.h in Headers */, + 8495F6841DB8F1EE00542124 /* LFAudioFrame.h in Headers */, + 8495F67F1DB8F1EE00542124 /* LFLiveVideoConfiguration.h in Headers */, + 8495F67E1DB8F1EE00542124 /* LFLiveAudioConfiguration.h in Headers */, + 8495F6831DB8F1EE00542124 /* LFLiveSession.h in Headers */, + 8495F66F1DB8F14600542124 /* LFLiveKitFramework.h in Headers */, + 8495F6731DB8F1EE00542124 /* LFAudioCapture.h in Headers */, + 8495F6741DB8F1EE00542124 /* LFVideoCapture.h in Headers */, + 8495F6751DB8F1EE00542124 /* LFAVEncoder.h in Headers */, + 8495F6761DB8F1EE00542124 /* LFMP4Atom.h in Headers */, + 8495F6771DB8F1EE00542124 /* LFNALUnit.h in Headers */, + 8495F6781DB8F1EE00542124 /* LFVideoEncoder.h in Headers */, + 8495F6791DB8F1EE00542124 /* LFAudioEncoding.h in Headers */, + 8495F67A1DB8F1EE00542124 /* LFH264VideoEncoder.h in Headers */, + 8495F67B1DB8F1EE00542124 /* LFHardwareAudioEncoder.h in Headers */, + 8495F67C1DB8F1EE00542124 /* LFHardwareVideoEncoder.h in Headers */, + 8495F67D1DB8F1EE00542124 /* LFVideoEncoding.h in Headers */, + 8495F6801DB8F1EE00542124 /* LFGPUImageBeautyFilter.h in Headers */, + 8495F6811DB8F1EE00542124 /* LFGPUImageEmptyFilter.h in Headers */, + 8495F6891DB8F1EE00542124 /* LFStreamingBuffer.h in Headers */, + 8495F68A1DB8F1EE00542124 /* LFStreamRTMPSocket.h in Headers */, + 8495F68B1DB8F1EE00542124 /* LFStreamSocket.h in Headers */, + 8495F68C1DB8F1EE00542124 /* NSMutableArray+LFAdd.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 84D8B38D1D7574D600752B56 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 84D8B5DE1D768B6E00752B56 /* LFLiveDebug.h in Headers */, + 843590CB1DD1FEB600811FC7 /* GPUImagePerlinNoiseFilter.h in Headers */, + 843591501DD1FEB600811FC7 /* bytes.h in Headers */, + 84D8B5CF1D768B6E00752B56 /* LFLiveAudioConfiguration.h in Headers */, + 843590FF1DD1FEB600811FC7 /* GPUImageSobelEdgeDetectionFilter.h in Headers */, + 8435907D1DD1FEB600811FC7 /* GPUImageHoughTransformLineDetector.h in Headers */, + 843590C71DD1FEB600811FC7 /* GPUImageOverlayBlendFilter.h in Headers */, + 84D8B5DA1D768B6E00752B56 /* LFAudioFrame.h in Headers */, + 8435911B1DD1FEB600811FC7 /* GPUImageThresholdEdgeDetectionFilter.h in Headers */, + 843591111DD1FEB600811FC7 /* GPUImageSubtractBlendFilter.h in Headers */, + 843590B51DD1FEB600811FC7 /* GPUImageMovie.h in Headers */, + 843590731DD1FEB600811FC7 /* GPUImageHighlightShadowTintFilter.h in Headers */, + 843590831DD1FEB600811FC7 /* GPUImageHueFilter.h in Headers */, + 843591591DD1FEB600811FC7 /* log.h in Headers */, + 843591091DD1FEB600811FC7 /* GPUImageSourceOverBlendFilter.h in Headers */, + 843590251DD1FEB600811FC7 /* GPUImageColorLocalBinaryPatternFilter.h in Headers */, + 843590391DD1FEB600811FC7 /* GPUImageDifferenceBlendFilter.h in Headers */, + 843591441DD1FEB600811FC7 /* GPUImageContext.h in Headers */, + 843590331DD1FEB600811FC7 /* GPUImageCrosshairGenerator.h in Headers */, + 84D8B5E01D768B6E00752B56 /* LFLiveStreamInfo.h in Headers */, + 843590471DD1FEB600811FC7 /* GPUImageErosionFilter.h in Headers */, + 84D8B5D11D768B6E00752B56 /* LFLiveVideoConfiguration.h in Headers */, + 8435907B1DD1FEB600811FC7 /* GPUImageHistogramGenerator.h in Headers */, + 8435901F1DD1FEB600811FC7 /* GPUImageColorConversion.h in Headers */, + 84358FF71DD1FEB600811FC7 /* GPUImage3x3ConvolutionFilter.h in Headers */, + 843590F11DD1FEB600811FC7 /* GPUImageSepiaFilter.h in Headers */, + 843590091DD1FEB600811FC7 /* GPUImageBoxBlurFilter.h in Headers */, + 843590E51DD1FEB600811FC7 /* GPUImageRGBErosionFilter.h in Headers */, + 8435912B1DD1FEB600811FC7 /* GPUImageTwoInputFilter.h in Headers */, + 8435900D1DD1FEB600811FC7 /* GPUImageBuffer.h in Headers */, + 8435912D1DD1FEB600811FC7 /* GPUImageTwoPassFilter.h in Headers */, + 8435908B1DD1FEB600811FC7 /* GPUImageKuwaharaRadius3Filter.h in Headers */, + 8435914C1DD1FEB600811FC7 /* GPUImageView.h in Headers */, + 843590F31DD1FEB600811FC7 /* GPUImageSharpenFilter.h in Headers */, + 84D8B5DC1D768B6E00752B56 /* LFFrame.h in Headers */, + 843591551DD1FEB600811FC7 /* handshake.h in Headers */, + 84D8B5D71D768B6E00752B56 /* LFLiveKit.h in Headers */, + 8435904D1DD1FEB600811FC7 /* GPUImageFalseColorFilter.h in Headers */, + 843590111DD1FEB600811FC7 /* GPUImageCannyEdgeDetectionFilter.h in Headers */, + 8435906F1DD1FEB600811FC7 /* GPUImageHazeFilter.h in Headers */, + 8435903F1DD1FEB600811FC7 /* GPUImageDirectionalSobelEdgeDetectionFilter.h in Headers */, + 843590631DD1FEB600811FC7 /* GPUImageGaussianSelectiveBlurFilter.h in Headers */, + 843591371DD1FEB600811FC7 /* GPUImageVignetteFilter.h in Headers */, + 843591071DD1FEB600811FC7 /* GPUImageSolidColorGenerator.h in Headers */, + 843590A71DD1FEB600811FC7 /* GPUImageMaskFilter.h in Headers */, + 843590431DD1FEB600811FC7 /* GPUImageDivideBlendFilter.h in Headers */, + 84D8B5D81D768B6E00752B56 /* LFLiveSession.h in Headers */, + 8435909B1DD1FEB600811FC7 /* GPUImageLookupFilter.h in Headers */, + 843591431DD1FEB600811FC7 /* GPUImageFramework.h in Headers */, + 843590A51DD1FEB600811FC7 /* GPUImageLuminosityBlendFilter.h in Headers */, + 843590D71DD1FEB600811FC7 /* GPUImagePolkaDotFilter.h in Headers */, + 843590B11DD1FEB600811FC7 /* GPUImageMotionBlurFilter.h in Headers */, + 843591171DD1FEB600811FC7 /* GPUImageTextureOutput.h in Headers */, + 843591351DD1FEB600811FC7 /* GPUImageVideoCamera.h in Headers */, + 843590D31DD1FEB600811FC7 /* GPUImagePoissonBlendFilter.h in Headers */, + 84D8B5E21D768B6E00752B56 /* LFVideoFrame.h in Headers */, + 843590D11DD1FEB600811FC7 /* GPUImagePixellatePositionFilter.h in Headers */, + 843590EB1DD1FEB600811FC7 /* GPUImageSaturationBlendFilter.h in Headers */, + 843590671DD1FEB600811FC7 /* GPUImageGrayscaleFilter.h in Headers */, + 843590F71DD1FEB600811FC7 /* GPUImageSingleComponentGaussianBlurFilter.h in Headers */, + 843590CF1DD1FEB600811FC7 /* GPUImagePixellateFilter.h in Headers */, + 843591411DD1FEB600811FC7 /* GPUImageZoomBlurFilter.h in Headers */, + 843590591DD1FEB600811FC7 /* GPUImageFramebuffer.h in Headers */, + 843590A91DD1FEB600811FC7 /* GPUImageMedianFilter.h in Headers */, + 8435910B1DD1FEB600811FC7 /* GPUImageSphereRefractionFilter.h in Headers */, + 843590BD1DD1FEB600811FC7 /* GPUImageNonMaximumSuppressionFilter.h in Headers */, + 843590B31DD1FEB600811FC7 /* GPUImageMotionDetector.h in Headers */, + 843590C91DD1FEB600811FC7 /* GPUImageParallelCoordinateLineTransformFilter.h in Headers */, + 843590ED1DD1FEB600811FC7 /* GPUImageSaturationFilter.h in Headers */, + 843590491DD1FEB600811FC7 /* GPUImageExclusionBlendFilter.h in Headers */, + 843590DB1DD1FEB600811FC7 /* GPUImagePrewittEdgeDetectionFilter.h in Headers */, + 843591231DD1FEB600811FC7 /* GPUImageToneCurveFilter.h in Headers */, + 843591291DD1FEB600811FC7 /* GPUImageTwoInputCrossTextureSamplingFilter.h in Headers */, + 843590071DD1FEB600811FC7 /* GPUImageBilateralFilter.h in Headers */, + 843591521DD1FEB600811FC7 /* dhgroups.h in Headers */, + 843590CD1DD1FEB600811FC7 /* GPUImagePinchDistortionFilter.h in Headers */, + 843591311DD1FEB600811FC7 /* GPUImageUIElement.h in Headers */, + 843591151DD1FEB600811FC7 /* GPUImageTextureInput.h in Headers */, + 843590E11DD1FEB600811FC7 /* GPUImageRGBClosingFilter.h in Headers */, + 843590911DD1FEB600811FC7 /* GPUImageLevelsFilter.h in Headers */, + 843590EF1DD1FEB600811FC7 /* GPUImageScreenBlendFilter.h in Headers */, + 84D8B5BB1D768B6E00752B56 /* LFAudioCapture.h in Headers */, + 8435907F1DD1FEB600811FC7 /* GPUImageHSBFilter.h in Headers */, + 843590E31DD1FEB600811FC7 /* GPUImageRGBDilationFilter.h in Headers */, + 8435911D1DD1FEB600811FC7 /* GPUImageThresholdedNonMaximumSuppressionFilter.h in Headers */, + 843590011DD1FEB600811FC7 /* GPUImageAmatorkaFilter.h in Headers */, + 843590B91DD1FEB600811FC7 /* GPUImageMultiplyBlendFilter.h in Headers */, + 84D8B5E61D768B6E00752B56 /* LFStreamRTMPSocket.h in Headers */, + 843590151DD1FEB600811FC7 /* GPUImageChromaKeyBlendFilter.h in Headers */, + 84358FF41DD1FEB600811FC7 /* GLProgram.h in Headers */, + 843590411DD1FEB600811FC7 /* GPUImageDissolveBlendFilter.h in Headers */, + 8435900F1DD1FEB600811FC7 /* GPUImageBulgeDistortionFilter.h in Headers */, + 8435908D1DD1FEB600811FC7 /* GPUImageLanczosResamplingFilter.h in Headers */, + 8435906D1DD1FEB600811FC7 /* GPUImageHarrisCornerDetectionFilter.h in Headers */, + 843591211DD1FEB600811FC7 /* GPUImageTiltShiftFilter.h in Headers */, + 843590531DD1FEB600811FC7 /* GPUImageFilterGroup.h in Headers */, + 8435901D1DD1FEB600811FC7 /* GPUImageColorBurnBlendFilter.h in Headers */, + 843590951DD1FEB600811FC7 /* GPUImageLinearBurnBlendFilter.h in Headers */, + 8435905B1DD1FEB600811FC7 /* GPUImageFramebufferCache.h in Headers */, + 843590D51DD1FEB600811FC7 /* GPUImagePolarPixellateFilter.h in Headers */, + 843591051DD1FEB600811FC7 /* GPUImageSolarizeFilter.h in Headers */, + 843590611DD1FEB600811FC7 /* GPUImageGaussianBlurPositionFilter.h in Headers */, + 843590311DD1FEB600811FC7 /* GPUImageCropFilter.h in Headers */, + 843590F51DD1FEB600811FC7 /* GPUImageShiTomasiFeatureDetectionFilter.h in Headers */, + 8435905D1DD1FEB600811FC7 /* GPUImageGammaFilter.h in Headers */, + 843590851DD1FEB600811FC7 /* GPUImageiOSBlurFilter.h in Headers */, + 843591481DD1FEB600811FC7 /* GPUImagePicture+TextureSubimage.h in Headers */, + 8435906B1DD1FEB600811FC7 /* GPUImageHardLightBlendFilter.h in Headers */, + 84358FFF1DD1FEB600811FC7 /* GPUImageAlphaBlendFilter.h in Headers */, + 8435913B1DD1FEB600811FC7 /* GPUImageWeakPixelInclusionFilter.h in Headers */, + 843590451DD1FEB600811FC7 /* GPUImageEmbossFilter.h in Headers */, + 843591461DD1FEB600811FC7 /* GPUImageMovieWriter.h in Headers */, + 8435909F1DD1FEB600811FC7 /* GPUImageLuminanceRangeFilter.h in Headers */, + 8435902D1DD1FEB600811FC7 /* GPUImageColourFASTSamplingOperation.h in Headers */, + 843590991DD1FEB600811FC7 /* GPUImageLocalBinaryPatternFilter.h in Headers */, + 8435915C1DD1FEB600811FC7 /* rtmp.h in Headers */, + 84D8B5C11D768B6E00752B56 /* LFMP4Atom.h in Headers */, + 843591541DD1FEB600811FC7 /* error.h in Headers */, + 8435903D1DD1FEB600811FC7 /* GPUImageDirectionalNonMaximumSuppressionFilter.h in Headers */, + 8435908F1DD1FEB600811FC7 /* GPUImageLaplacianFilter.h in Headers */, + 843590AB1DD1FEB600811FC7 /* GPUImageMissEtikateFilter.h in Headers */, + 843591331DD1FEB600811FC7 /* GPUImageUnsharpMaskFilter.h in Headers */, + 843591011DD1FEB600811FC7 /* GPUImageSoftEleganceFilter.h in Headers */, + 843591251DD1FEB600811FC7 /* GPUImageToonFilter.h in Headers */, + 843590371DD1FEB600811FC7 /* GPUImageDarkenBlendFilter.h in Headers */, + 84D8B5D31D768B6E00752B56 /* LFGPUImageBeautyFilter.h in Headers */, + 84D8B5BF1D768B6E00752B56 /* LFAVEncoder.h in Headers */, + 843590871DD1FEB600811FC7 /* GPUImageJFAVoronoiFilter.h in Headers */, + 8435902B1DD1FEB600811FC7 /* GPUImageColourFASTFeatureDetector.h in Headers */, + 8435904F1DD1FEB600811FC7 /* GPUImageFASTCornerDetectionFilter.h in Headers */, + 84D8B5C51D768B6E00752B56 /* LFVideoEncoder.h in Headers */, + 843590191DD1FEB600811FC7 /* GPUImageClosingFilter.h in Headers */, + 843590551DD1FEB600811FC7 /* GPUImageFilterPipeline.h in Headers */, + 8435913F1DD1FEB600811FC7 /* GPUImageXYDerivativeFilter.h in Headers */, + 843590791DD1FEB600811FC7 /* GPUImageHistogramFilter.h in Headers */, + 843590E71DD1FEB600811FC7 /* GPUImageRGBFilter.h in Headers */, + 8435903B1DD1FEB600811FC7 /* GPUImageDilationFilter.h in Headers */, + 843590AD1DD1FEB600811FC7 /* GPUImageMonochromeFilter.h in Headers */, + 843590931DD1FEB600811FC7 /* GPUImageLightenBlendFilter.h in Headers */, + 843590271DD1FEB600811FC7 /* GPUImageColorMatrixFilter.h in Headers */, + 843591391DD1FEB600811FC7 /* GPUImageVoronoiConsumerFilter.h in Headers */, + 843590751DD1FEB600811FC7 /* GPUImageHighPassFilter.h in Headers */, + 843591271DD1FEB600811FC7 /* GPUImageTransformFilter.h in Headers */, + 843590DD1DD1FEB600811FC7 /* GPUImageRawDataInput.h in Headers */, + 8435914F1DD1FEB600811FC7 /* amf.h in Headers */, + 84358FFD1DD1FEB600811FC7 /* GPUImageAddBlendFilter.h in Headers */, + 843591131DD1FEB600811FC7 /* GPUImageSwirlFilter.h in Headers */, + 843590C51DD1FEB600811FC7 /* GPUImageOutput.h in Headers */, + 843590DF1DD1FEB600811FC7 /* GPUImageRawDataOutput.h in Headers */, + 843590351DD1FEB600811FC7 /* GPUImageCrosshatchFilter.h in Headers */, + 843590A31DD1FEB600811FC7 /* GPUImageLuminosity.h in Headers */, + 84D8B5D51D768B6E00752B56 /* LFGPUImageEmptyFilter.h in Headers */, + 84D8B5C71D768B6E00752B56 /* LFAudioEncoding.h in Headers */, + 843590211DD1FEB600811FC7 /* GPUImageColorDodgeBlendFilter.h in Headers */, + 843590771DD1FEB600811FC7 /* GPUImageHistogramEqualizationFilter.h in Headers */, + 843590231DD1FEB600811FC7 /* GPUImageColorInvertFilter.h in Headers */, + 8435913D1DD1FEB600811FC7 /* GPUImageWhiteBalanceFilter.h in Headers */, + 8435911F1DD1FEB600811FC7 /* GPUImageThresholdSketchFilter.h in Headers */, + 843590E91DD1FEB600811FC7 /* GPUImageRGBOpeningFilter.h in Headers */, + 843590651DD1FEB600811FC7 /* GPUImageGlassSphereFilter.h in Headers */, + 84358FF91DD1FEB600811FC7 /* GPUImage3x3TextureSamplingFilter.h in Headers */, + 843590BF1DD1FEB600811FC7 /* GPUImageNormalBlendFilter.h in Headers */, + 843590B71DD1FEB600811FC7 /* GPUImageMovieComposition.h in Headers */, + 84D8B5E91D768B6E00752B56 /* NSMutableArray+LFAdd.h in Headers */, + 8435910F1DD1FEB600811FC7 /* GPUImageStretchDistortionFilter.h in Headers */, + 84D8B5CC1D768B6E00752B56 /* LFHardwareVideoEncoder.h in Headers */, + 843591191DD1FEB600811FC7 /* GPUImageThreeInputFilter.h in Headers */, + 843591511DD1FEB600811FC7 /* dh.h in Headers */, + 84D8B5BD1D768B6E00752B56 /* LFVideoCapture.h in Headers */, + 8435915D1DD1FEB600811FC7 /* rtmp_sys.h in Headers */, + 843590C31DD1FEB600811FC7 /* GPUImageOpeningFilter.h in Headers */, + 8435901B1DD1FEB600811FC7 /* GPUImageColorBlendFilter.h in Headers */, + 843590F91DD1FEB600811FC7 /* GPUImageSketchFilter.h in Headers */, + 84D8B5E81D768B6E00752B56 /* LFStreamSocket.h in Headers */, + 84D8B5C41D768B6E00752B56 /* LFNALUnit.h in Headers */, + 843591031DD1FEB600811FC7 /* GPUImageSoftLightBlendFilter.h in Headers */, + 843590031DD1FEB600811FC7 /* GPUImageAverageColor.h in Headers */, + 843590571DD1FEB600811FC7 /* GPUImageFourInputFilter.h in Headers */, + 8435909D1DD1FEB600811FC7 /* GPUImageLowPassFilter.h in Headers */, + 84358FF61DD1FEB600811FC7 /* GPUImage.h in Headers */, + 84D8B5CA1D768B6E00752B56 /* LFHardwareAudioEncoder.h in Headers */, + 843590891DD1FEB600811FC7 /* GPUImageKuwaharaFilter.h in Headers */, + 8435900B1DD1FEB600811FC7 /* GPUImageBrightnessFilter.h in Headers */, + 843591571DD1FEB600811FC7 /* http.h in Headers */, + 843590BB1DD1FEB600811FC7 /* GPUImageNobleCornerDetectionFilter.h in Headers */, + 843590971DD1FEB600811FC7 /* GPUImageLineGenerator.h in Headers */, + 84D8B5CE1D768B6E00752B56 /* LFVideoEncoding.h in Headers */, + 843590051DD1FEB600811FC7 /* GPUImageAverageLuminanceThresholdFilter.h in Headers */, + 843590511DD1FEB600811FC7 /* GPUImageFilter.h in Headers */, + 843590691DD1FEB600811FC7 /* GPUImageHalftoneFilter.h in Headers */, + 84358FFB1DD1FEB600811FC7 /* GPUImageAdaptiveThresholdFilter.h in Headers */, + 843590291DD1FEB600811FC7 /* GPUImageColorPackingFilter.h in Headers */, + 843590131DD1FEB600811FC7 /* GPUImageCGAColorspaceFilter.h in Headers */, + 84D8B5E41D768B6E00752B56 /* LFStreamingBuffer.h in Headers */, + 8435905F1DD1FEB600811FC7 /* GPUImageGaussianBlurFilter.h in Headers */, + 8435910D1DD1FEB600811FC7 /* GPUImageStillCamera.h in Headers */, + 8435912F1DD1FEB600811FC7 /* GPUImageTwoPassTextureSamplingFilter.h in Headers */, + 8435904B1DD1FEB600811FC7 /* GPUImageExposureFilter.h in Headers */, + 8435902F1DD1FEB600811FC7 /* GPUImageContrastFilter.h in Headers */, + 843590FB1DD1FEB600811FC7 /* GPUImageSkinToneFilter.h in Headers */, + 843590811DD1FEB600811FC7 /* GPUImageHueBlendFilter.h in Headers */, + 843590A11DD1FEB600811FC7 /* GPUImageLuminanceThresholdFilter.h in Headers */, + 843590AF1DD1FEB600811FC7 /* GPUImageMosaicFilter.h in Headers */, + 843590171DD1FEB600811FC7 /* GPUImageChromaKeyFilter.h in Headers */, + 843590711DD1FEB600811FC7 /* GPUImageHighlightShadowFilter.h in Headers */, + 84D8B5C81D768B6E00752B56 /* LFH264VideoEncoder.h in Headers */, + 843590C11DD1FEB600811FC7 /* GPUImageOpacityFilter.h in Headers */, + 843590D91DD1FEB600811FC7 /* GPUImagePosterizeFilter.h in Headers */, + 843590FD1DD1FEB600811FC7 /* GPUImageSmoothToonFilter.h in Headers */, + 8435914A1DD1FEB600811FC7 /* GPUImagePicture.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 8495F66A1DB8F14600542124 /* LFLiveKitFramework */ = { + isa = PBXNativeTarget; + buildConfigurationList = 8495F6701DB8F14600542124 /* Build configuration list for PBXNativeTarget "LFLiveKitFramework" */; + buildPhases = ( + 8495F6661DB8F14600542124 /* Sources */, + 8495F6671DB8F14600542124 /* Frameworks */, + 8495F6681DB8F14600542124 /* Headers */, + 8495F6691DB8F14600542124 /* Resources */, + 84D0037D1DB9023F00560583 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = LFLiveKitFramework; + productName = LFLiveKitFramework; + productReference = 8495F66B1DB8F14600542124 /* LFLiveKit.framework */; + productType = "com.apple.product-type.framework"; + }; + 84D8B38F1D7574D600752B56 /* LFLiveKit */ = { + isa = PBXNativeTarget; + buildConfigurationList = 84D8B3981D7574D600752B56 /* Build configuration list for PBXNativeTarget "LFLiveKit" */; + buildPhases = ( + 84D8B38B1D7574D600752B56 /* Sources */, + 84D8B38C1D7574D600752B56 /* Frameworks */, + 84D8B38D1D7574D600752B56 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = LFLiveKit; + productName = LFLiveKit; + productReference = 84D8B3901D7574D600752B56 /* LFLiveKit.framework */; + productType = "com.apple.product-type.framework"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 84D8B3871D7574D600752B56 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0730; + ORGANIZATIONNAME = admin; + TargetAttributes = { + 8495F66A1DB8F14600542124 = { + CreatedOnToolsVersion = 8.0; + ProvisioningStyle = Automatic; + }; + 84D003751DB8FE1000560583 = { + CreatedOnToolsVersion = 8.0; + DevelopmentTeam = G497YX6CBT; + ProvisioningStyle = Automatic; + }; + 84D8B38F1D7574D600752B56 = { + CreatedOnToolsVersion = 7.3.1; + }; + }; + }; + buildConfigurationList = 84D8B38A1D7574D600752B56 /* Build configuration list for PBXProject "LFLiveKit" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 84D8B3861D7574D600752B56; + productRefGroup = 84D8B3911D7574D600752B56 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 84D8B38F1D7574D600752B56 /* LFLiveKit */, + 8495F66A1DB8F14600542124 /* LFLiveKitFramework */, + 84D003751DB8FE1000560583 /* LFLiveKitFramework-universal */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 8495F6691DB8F14600542124 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 84D0037B1DB8FE1C00560583 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "../scripts/build-universal-framework.sh\n"; + }; + 84D0037D1DB9023F00560583 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "echo \"${env}\""; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 8495F6661DB8F14600542124 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 843592181DD20A9700811FC7 /* amf.c in Sources */, + 843592191DD20A9700811FC7 /* error.c in Sources */, + 8435921A1DD20A9700811FC7 /* hashswf.c in Sources */, + 8435921B1DD20A9700811FC7 /* log.c in Sources */, + 8435921C1DD20A9700811FC7 /* parseurl.c in Sources */, + 8435921D1DD20A9700811FC7 /* rtmp.c in Sources */, + 8435916C1DD20A7E00811FC7 /* GLProgram.m in Sources */, + 8435916D1DD20A7E00811FC7 /* GPUImage3x3ConvolutionFilter.m in Sources */, + 8435916E1DD20A7E00811FC7 /* GPUImage3x3TextureSamplingFilter.m in Sources */, + 8435916F1DD20A7E00811FC7 /* GPUImageAdaptiveThresholdFilter.m in Sources */, + 843591701DD20A7E00811FC7 /* GPUImageAddBlendFilter.m in Sources */, + 843591711DD20A7E00811FC7 /* GPUImageAlphaBlendFilter.m in Sources */, + 843591721DD20A7E00811FC7 /* GPUImageAmatorkaFilter.m in Sources */, + 843591731DD20A7E00811FC7 /* GPUImageAverageColor.m in Sources */, + 843591741DD20A7E00811FC7 /* GPUImageAverageLuminanceThresholdFilter.m in Sources */, + 843591751DD20A7E00811FC7 /* GPUImageBilateralFilter.m in Sources */, + 843591761DD20A7E00811FC7 /* GPUImageBoxBlurFilter.m in Sources */, + 843591771DD20A7E00811FC7 /* GPUImageBrightnessFilter.m in Sources */, + 843591781DD20A7E00811FC7 /* GPUImageBuffer.m in Sources */, + 843591791DD20A7E00811FC7 /* GPUImageBulgeDistortionFilter.m in Sources */, + 8435917A1DD20A7E00811FC7 /* GPUImageCannyEdgeDetectionFilter.m in Sources */, + 8435917B1DD20A7E00811FC7 /* GPUImageCGAColorspaceFilter.m in Sources */, + 8435917C1DD20A7E00811FC7 /* GPUImageChromaKeyBlendFilter.m in Sources */, + 8435917D1DD20A7E00811FC7 /* GPUImageChromaKeyFilter.m in Sources */, + 8435917E1DD20A7E00811FC7 /* GPUImageClosingFilter.m in Sources */, + 8435917F1DD20A7E00811FC7 /* GPUImageColorBlendFilter.m in Sources */, + 843591801DD20A7E00811FC7 /* GPUImageColorBurnBlendFilter.m in Sources */, + 843591811DD20A7E00811FC7 /* GPUImageColorConversion.m in Sources */, + 843591821DD20A7E00811FC7 /* GPUImageColorDodgeBlendFilter.m in Sources */, + 843591831DD20A7E00811FC7 /* GPUImageColorInvertFilter.m in Sources */, + 843591841DD20A7E00811FC7 /* GPUImageColorLocalBinaryPatternFilter.m in Sources */, + 843591851DD20A7E00811FC7 /* GPUImageColorMatrixFilter.m in Sources */, + 843591861DD20A7E00811FC7 /* GPUImageColorPackingFilter.m in Sources */, + 843591871DD20A7E00811FC7 /* GPUImageColourFASTFeatureDetector.m in Sources */, + 843591881DD20A7E00811FC7 /* GPUImageColourFASTSamplingOperation.m in Sources */, + 843591891DD20A7E00811FC7 /* GPUImageContrastFilter.m in Sources */, + 8435918A1DD20A7E00811FC7 /* GPUImageCropFilter.m in Sources */, + 8435918B1DD20A7E00811FC7 /* GPUImageCrosshairGenerator.m in Sources */, + 8435918C1DD20A7E00811FC7 /* GPUImageCrosshatchFilter.m in Sources */, + 8435918D1DD20A7E00811FC7 /* GPUImageDarkenBlendFilter.m in Sources */, + 8435918E1DD20A7E00811FC7 /* GPUImageDifferenceBlendFilter.m in Sources */, + 8435918F1DD20A7E00811FC7 /* GPUImageDilationFilter.m in Sources */, + 843591901DD20A7E00811FC7 /* GPUImageDirectionalNonMaximumSuppressionFilter.m in Sources */, + 843591911DD20A7E00811FC7 /* GPUImageDirectionalSobelEdgeDetectionFilter.m in Sources */, + 843591921DD20A7E00811FC7 /* GPUImageDissolveBlendFilter.m in Sources */, + 843591931DD20A7E00811FC7 /* GPUImageDivideBlendFilter.m in Sources */, + 843591941DD20A7E00811FC7 /* GPUImageEmbossFilter.m in Sources */, + 843591951DD20A7E00811FC7 /* GPUImageErosionFilter.m in Sources */, + 843591961DD20A7E00811FC7 /* GPUImageExclusionBlendFilter.m in Sources */, + 843591971DD20A7E00811FC7 /* GPUImageExposureFilter.m in Sources */, + 843591981DD20A7E00811FC7 /* GPUImageFalseColorFilter.m in Sources */, + 843591991DD20A7E00811FC7 /* GPUImageFASTCornerDetectionFilter.m in Sources */, + 8435919A1DD20A7E00811FC7 /* GPUImageFilter.m in Sources */, + 8435919B1DD20A7E00811FC7 /* GPUImageFilterGroup.m in Sources */, + 8435919C1DD20A7E00811FC7 /* GPUImageFilterPipeline.m in Sources */, + 8435919D1DD20A7E00811FC7 /* GPUImageFourInputFilter.m in Sources */, + 8435919E1DD20A7E00811FC7 /* GPUImageFramebuffer.m in Sources */, + 8435919F1DD20A7E00811FC7 /* GPUImageFramebufferCache.m in Sources */, + 843591A01DD20A7E00811FC7 /* GPUImageGammaFilter.m in Sources */, + 843591A11DD20A7E00811FC7 /* GPUImageGaussianBlurFilter.m in Sources */, + 843591A21DD20A7E00811FC7 /* GPUImageGaussianBlurPositionFilter.m in Sources */, + 843591A31DD20A7E00811FC7 /* GPUImageGaussianSelectiveBlurFilter.m in Sources */, + 843591A41DD20A7E00811FC7 /* GPUImageGlassSphereFilter.m in Sources */, + 843591A51DD20A7E00811FC7 /* GPUImageGrayscaleFilter.m in Sources */, + 843591A61DD20A7F00811FC7 /* GPUImageHalftoneFilter.m in Sources */, + 843591A71DD20A7F00811FC7 /* GPUImageHardLightBlendFilter.m in Sources */, + 843591A81DD20A7F00811FC7 /* GPUImageHarrisCornerDetectionFilter.m in Sources */, + 843591A91DD20A7F00811FC7 /* GPUImageHazeFilter.m in Sources */, + 843591AA1DD20A7F00811FC7 /* GPUImageHighlightShadowFilter.m in Sources */, + 843591AB1DD20A7F00811FC7 /* GPUImageHighlightShadowTintFilter.m in Sources */, + 843591AC1DD20A7F00811FC7 /* GPUImageHighPassFilter.m in Sources */, + 843591AD1DD20A7F00811FC7 /* GPUImageHistogramEqualizationFilter.m in Sources */, + 843591AE1DD20A7F00811FC7 /* GPUImageHistogramFilter.m in Sources */, + 843591AF1DD20A7F00811FC7 /* GPUImageHistogramGenerator.m in Sources */, + 843591B01DD20A7F00811FC7 /* GPUImageHoughTransformLineDetector.m in Sources */, + 843591B11DD20A7F00811FC7 /* GPUImageHSBFilter.m in Sources */, + 843591B21DD20A7F00811FC7 /* GPUImageHueBlendFilter.m in Sources */, + 843591B31DD20A7F00811FC7 /* GPUImageHueFilter.m in Sources */, + 843591B41DD20A7F00811FC7 /* GPUImageiOSBlurFilter.m in Sources */, + 843591B51DD20A7F00811FC7 /* GPUImageJFAVoronoiFilter.m in Sources */, + 843591B61DD20A7F00811FC7 /* GPUImageKuwaharaFilter.m in Sources */, + 843591B71DD20A7F00811FC7 /* GPUImageKuwaharaRadius3Filter.m in Sources */, + 843591B81DD20A7F00811FC7 /* GPUImageLanczosResamplingFilter.m in Sources */, + 843591B91DD20A7F00811FC7 /* GPUImageLaplacianFilter.m in Sources */, + 843591BA1DD20A7F00811FC7 /* GPUImageLevelsFilter.m in Sources */, + 843591BB1DD20A7F00811FC7 /* GPUImageLightenBlendFilter.m in Sources */, + 843591BC1DD20A7F00811FC7 /* GPUImageLinearBurnBlendFilter.m in Sources */, + 843591BD1DD20A7F00811FC7 /* GPUImageLineGenerator.m in Sources */, + 843591BE1DD20A7F00811FC7 /* GPUImageLocalBinaryPatternFilter.m in Sources */, + 843591BF1DD20A7F00811FC7 /* GPUImageLookupFilter.m in Sources */, + 843591C01DD20A7F00811FC7 /* GPUImageLowPassFilter.m in Sources */, + 843591C11DD20A7F00811FC7 /* GPUImageLuminanceRangeFilter.m in Sources */, + 843591C21DD20A7F00811FC7 /* GPUImageLuminanceThresholdFilter.m in Sources */, + 843591C31DD20A7F00811FC7 /* GPUImageLuminosity.m in Sources */, + 843591C41DD20A7F00811FC7 /* GPUImageLuminosityBlendFilter.m in Sources */, + 843591C51DD20A7F00811FC7 /* GPUImageMaskFilter.m in Sources */, + 843591C61DD20A7F00811FC7 /* GPUImageMedianFilter.m in Sources */, + 843591C71DD20A7F00811FC7 /* GPUImageMissEtikateFilter.m in Sources */, + 843591C81DD20A7F00811FC7 /* GPUImageMonochromeFilter.m in Sources */, + 843591C91DD20A7F00811FC7 /* GPUImageMosaicFilter.m in Sources */, + 843591CA1DD20A7F00811FC7 /* GPUImageMotionBlurFilter.m in Sources */, + 843591CB1DD20A7F00811FC7 /* GPUImageMotionDetector.m in Sources */, + 843591CC1DD20A7F00811FC7 /* GPUImageMovie.m in Sources */, + 843591CD1DD20A7F00811FC7 /* GPUImageMovieComposition.m in Sources */, + 843591CE1DD20A7F00811FC7 /* GPUImageMultiplyBlendFilter.m in Sources */, + 843591CF1DD20A7F00811FC7 /* GPUImageNobleCornerDetectionFilter.m in Sources */, + 843591D01DD20A7F00811FC7 /* GPUImageNonMaximumSuppressionFilter.m in Sources */, + 843591D11DD20A7F00811FC7 /* GPUImageNormalBlendFilter.m in Sources */, + 843591D21DD20A7F00811FC7 /* GPUImageOpacityFilter.m in Sources */, + 843591D31DD20A7F00811FC7 /* GPUImageOpeningFilter.m in Sources */, + 843591D41DD20A7F00811FC7 /* GPUImageOutput.m in Sources */, + 843591D51DD20A7F00811FC7 /* GPUImageOverlayBlendFilter.m in Sources */, + 843591D61DD20A7F00811FC7 /* GPUImageParallelCoordinateLineTransformFilter.m in Sources */, + 843591D71DD20A7F00811FC7 /* GPUImagePerlinNoiseFilter.m in Sources */, + 843591D81DD20A7F00811FC7 /* GPUImagePinchDistortionFilter.m in Sources */, + 843591D91DD20A7F00811FC7 /* GPUImagePixellateFilter.m in Sources */, + 843591DA1DD20A7F00811FC7 /* GPUImagePixellatePositionFilter.m in Sources */, + 843591DB1DD20A7F00811FC7 /* GPUImagePoissonBlendFilter.m in Sources */, + 843591DC1DD20A7F00811FC7 /* GPUImagePolarPixellateFilter.m in Sources */, + 843591DD1DD20A7F00811FC7 /* GPUImagePolkaDotFilter.m in Sources */, + 843591DE1DD20A7F00811FC7 /* GPUImagePosterizeFilter.m in Sources */, + 843591DF1DD20A7F00811FC7 /* GPUImagePrewittEdgeDetectionFilter.m in Sources */, + 843591E01DD20A7F00811FC7 /* GPUImageRawDataInput.m in Sources */, + 843591E11DD20A7F00811FC7 /* GPUImageRawDataOutput.m in Sources */, + 843591E21DD20A7F00811FC7 /* GPUImageRGBClosingFilter.m in Sources */, + 843591E31DD20A7F00811FC7 /* GPUImageRGBDilationFilter.m in Sources */, + 843591E41DD20A7F00811FC7 /* GPUImageRGBErosionFilter.m in Sources */, + 843591E51DD20A7F00811FC7 /* GPUImageRGBFilter.m in Sources */, + 843591E61DD20A7F00811FC7 /* GPUImageRGBOpeningFilter.m in Sources */, + 843591E71DD20A7F00811FC7 /* GPUImageSaturationBlendFilter.m in Sources */, + 843591E81DD20A7F00811FC7 /* GPUImageSaturationFilter.m in Sources */, + 843591E91DD20A7F00811FC7 /* GPUImageScreenBlendFilter.m in Sources */, + 843591EA1DD20A7F00811FC7 /* GPUImageSepiaFilter.m in Sources */, + 843591EB1DD20A7F00811FC7 /* GPUImageSharpenFilter.m in Sources */, + 843591EC1DD20A7F00811FC7 /* GPUImageShiTomasiFeatureDetectionFilter.m in Sources */, + 843591ED1DD20A7F00811FC7 /* GPUImageSingleComponentGaussianBlurFilter.m in Sources */, + 843591EE1DD20A7F00811FC7 /* GPUImageSketchFilter.m in Sources */, + 843591EF1DD20A7F00811FC7 /* GPUImageSkinToneFilter.m in Sources */, + 843591F01DD20A7F00811FC7 /* GPUImageSmoothToonFilter.m in Sources */, + 843591F11DD20A7F00811FC7 /* GPUImageSobelEdgeDetectionFilter.m in Sources */, + 843591F21DD20A7F00811FC7 /* GPUImageSoftEleganceFilter.m in Sources */, + 843591F31DD20A7F00811FC7 /* GPUImageSoftLightBlendFilter.m in Sources */, + 843591F41DD20A7F00811FC7 /* GPUImageSolarizeFilter.m in Sources */, + 843591F51DD20A7F00811FC7 /* GPUImageSolidColorGenerator.m in Sources */, + 843591F61DD20A7F00811FC7 /* GPUImageSourceOverBlendFilter.m in Sources */, + 843591F71DD20A7F00811FC7 /* GPUImageSphereRefractionFilter.m in Sources */, + 843591F81DD20A7F00811FC7 /* GPUImageStillCamera.m in Sources */, + 843591F91DD20A7F00811FC7 /* GPUImageStretchDistortionFilter.m in Sources */, + 843591FA1DD20A7F00811FC7 /* GPUImageSubtractBlendFilter.m in Sources */, + 843591FB1DD20A7F00811FC7 /* GPUImageSwirlFilter.m in Sources */, + 843591FC1DD20A7F00811FC7 /* GPUImageTextureInput.m in Sources */, + 843591FD1DD20A7F00811FC7 /* GPUImageTextureOutput.m in Sources */, + 843591FE1DD20A7F00811FC7 /* GPUImageThreeInputFilter.m in Sources */, + 843591FF1DD20A7F00811FC7 /* GPUImageThresholdEdgeDetectionFilter.m in Sources */, + 843592001DD20A7F00811FC7 /* GPUImageThresholdedNonMaximumSuppressionFilter.m in Sources */, + 843592011DD20A7F00811FC7 /* GPUImageThresholdSketchFilter.m in Sources */, + 843592021DD20A7F00811FC7 /* GPUImageTiltShiftFilter.m in Sources */, + 843592031DD20A7F00811FC7 /* GPUImageToneCurveFilter.m in Sources */, + 843592041DD20A7F00811FC7 /* GPUImageToonFilter.m in Sources */, + 843592051DD20A7F00811FC7 /* GPUImageTransformFilter.m in Sources */, + 843592061DD20A7F00811FC7 /* GPUImageTwoInputCrossTextureSamplingFilter.m in Sources */, + 843592071DD20A7F00811FC7 /* GPUImageTwoInputFilter.m in Sources */, + 843592081DD20A7F00811FC7 /* GPUImageTwoPassFilter.m in Sources */, + 843592091DD20A7F00811FC7 /* GPUImageTwoPassTextureSamplingFilter.m in Sources */, + 8435920A1DD20A7F00811FC7 /* GPUImageUIElement.m in Sources */, + 8435920B1DD20A7F00811FC7 /* GPUImageUnsharpMaskFilter.m in Sources */, + 8435920C1DD20A7F00811FC7 /* GPUImageVideoCamera.m in Sources */, + 8435920D1DD20A7F00811FC7 /* GPUImageVignetteFilter.m in Sources */, + 8435920E1DD20A7F00811FC7 /* GPUImageVoronoiConsumerFilter.m in Sources */, + 8435920F1DD20A7F00811FC7 /* GPUImageWeakPixelInclusionFilter.m in Sources */, + 843592101DD20A7F00811FC7 /* GPUImageWhiteBalanceFilter.m in Sources */, + 843592111DD20A7F00811FC7 /* GPUImageXYDerivativeFilter.m in Sources */, + 843592121DD20A7F00811FC7 /* GPUImageZoomBlurFilter.m in Sources */, + 843592131DD20A7F00811FC7 /* GPUImageContext.m in Sources */, + 843592141DD20A7F00811FC7 /* GPUImageMovieWriter.m in Sources */, + 843592151DD20A7F00811FC7 /* GPUImagePicture+TextureSubimage.m in Sources */, + 843592161DD20A7F00811FC7 /* GPUImagePicture.m in Sources */, + 843592171DD20A7F00811FC7 /* GPUImageView.m in Sources */, + 84D0036F1DB8F88F00560583 /* LFNALUnit.cpp in Sources */, + 8495F68D1DB8F27000542124 /* LFAudioCapture.m in Sources */, + 8495F68E1DB8F27000542124 /* LFVideoCapture.m in Sources */, + 8495F68F1DB8F27000542124 /* LFAVEncoder.mm in Sources */, + 8495F6901DB8F27000542124 /* LFMP4Atom.m in Sources */, + 8495F6911DB8F27000542124 /* LFVideoEncoder.m in Sources */, + 8495F6921DB8F27000542124 /* LFH264VideoEncoder.mm in Sources */, + 8495F6931DB8F27000542124 /* LFHardwareAudioEncoder.m in Sources */, + 8495F6941DB8F27000542124 /* LFHardwareVideoEncoder.m in Sources */, + 8495F6951DB8F27000542124 /* LFLiveAudioConfiguration.m in Sources */, + 8495F6961DB8F27000542124 /* LFLiveVideoConfiguration.m in Sources */, + 8495F6971DB8F27000542124 /* LFGPUImageBeautyFilter.m in Sources */, + 8495F6981DB8F27000542124 /* LFGPUImageEmptyFilter.m in Sources */, + 8495F6991DB8F27000542124 /* LFLiveSession.m in Sources */, + 8495F69A1DB8F27000542124 /* LFAudioFrame.m in Sources */, + 8495F69B1DB8F27000542124 /* LFFrame.m in Sources */, + 8495F69C1DB8F27000542124 /* LFLiveDebug.m in Sources */, + 8495F69D1DB8F27000542124 /* LFLiveStreamInfo.m in Sources */, + 8495F69E1DB8F27000542124 /* LFVideoFrame.m in Sources */, + 8495F69F1DB8F27000542124 /* LFStreamingBuffer.m in Sources */, + 8495F6A01DB8F27000542124 /* LFStreamRtmpSocket.m in Sources */, + 8495F6A11DB8F27000542124 /* NSMutableArray+LFAdd.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 84D8B38B1D7574D600752B56 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 843591581DD1FEB600811FC7 /* log.c in Sources */, + 843590D21DD1FEB600811FC7 /* GPUImagePixellatePositionFilter.m in Sources */, + 843591041DD1FEB600811FC7 /* GPUImageSoftLightBlendFilter.m in Sources */, + 8435909A1DD1FEB600811FC7 /* GPUImageLocalBinaryPatternFilter.m in Sources */, + 843590F61DD1FEB600811FC7 /* GPUImageShiTomasiFeatureDetectionFilter.m in Sources */, + 8435910A1DD1FEB600811FC7 /* GPUImageSourceOverBlendFilter.m in Sources */, + 843590981DD1FEB600811FC7 /* GPUImageLineGenerator.m in Sources */, + 843591381DD1FEB600811FC7 /* GPUImageVignetteFilter.m in Sources */, + 8435903C1DD1FEB600811FC7 /* GPUImageDilationFilter.m in Sources */, + 84D8B5D41D768B6E00752B56 /* LFGPUImageBeautyFilter.m in Sources */, + 84D8B5DD1D768B6E00752B56 /* LFFrame.m in Sources */, + 8435910E1DD1FEB600811FC7 /* GPUImageStillCamera.m in Sources */, + 84D8B5DF1D768B6E00752B56 /* LFLiveDebug.m in Sources */, + 843591451DD1FEB600811FC7 /* GPUImageContext.m in Sources */, + 843590141DD1FEB600811FC7 /* GPUImageCGAColorspaceFilter.m in Sources */, + 843590B21DD1FEB600811FC7 /* GPUImageMotionBlurFilter.m in Sources */, + 8435905E1DD1FEB600811FC7 /* GPUImageGammaFilter.m in Sources */, + 8435911A1DD1FEB600811FC7 /* GPUImageThreeInputFilter.m in Sources */, + 843590061DD1FEB600811FC7 /* GPUImageAverageLuminanceThresholdFilter.m in Sources */, + 843590481DD1FEB600811FC7 /* GPUImageErosionFilter.m in Sources */, + 843590601DD1FEB600811FC7 /* GPUImageGaussianBlurFilter.m in Sources */, + 843590A01DD1FEB600811FC7 /* GPUImageLuminanceRangeFilter.m in Sources */, + 843590841DD1FEB600811FC7 /* GPUImageHueFilter.m in Sources */, + 843590381DD1FEB600811FC7 /* GPUImageDarkenBlendFilter.m in Sources */, + 843591061DD1FEB600811FC7 /* GPUImageSolarizeFilter.m in Sources */, + 843590341DD1FEB600811FC7 /* GPUImageCrosshairGenerator.m in Sources */, + 843590AA1DD1FEB600811FC7 /* GPUImageMedianFilter.m in Sources */, + 843591001DD1FEB600811FC7 /* GPUImageSobelEdgeDetectionFilter.m in Sources */, + 843590DA1DD1FEB600811FC7 /* GPUImagePosterizeFilter.m in Sources */, + 8435900A1DD1FEB600811FC7 /* GPUImageBoxBlurFilter.m in Sources */, + 843590541DD1FEB600811FC7 /* GPUImageFilterGroup.m in Sources */, + 8435908C1DD1FEB600811FC7 /* GPUImageKuwaharaRadius3Filter.m in Sources */, + 843590221DD1FEB600811FC7 /* GPUImageColorDodgeBlendFilter.m in Sources */, + 843590FE1DD1FEB600811FC7 /* GPUImageSmoothToonFilter.m in Sources */, + 8435915A1DD1FEB600811FC7 /* parseurl.c in Sources */, + 84D8B5BE1D768B6E00752B56 /* LFVideoCapture.m in Sources */, + 84D8B5DB1D768B6E00752B56 /* LFAudioFrame.m in Sources */, + 8435912A1DD1FEB600811FC7 /* GPUImageTwoInputCrossTextureSamplingFilter.m in Sources */, + 843590161DD1FEB600811FC7 /* GPUImageChromaKeyBlendFilter.m in Sources */, + 84D8B5E11D768B6E00752B56 /* LFLiveStreamInfo.m in Sources */, + 8435904A1DD1FEB600811FC7 /* GPUImageExclusionBlendFilter.m in Sources */, + 84D8B5C31D768B6E00752B56 /* LFNALUnit.cpp in Sources */, + 84D8B5C01D768B6E00752B56 /* LFAVEncoder.mm in Sources */, + 843591261DD1FEB600811FC7 /* GPUImageToonFilter.m in Sources */, + 843590FC1DD1FEB600811FC7 /* GPUImageSkinToneFilter.m in Sources */, + 8435906A1DD1FEB600811FC7 /* GPUImageHalftoneFilter.m in Sources */, + 843590261DD1FEB600811FC7 /* GPUImageColorLocalBinaryPatternFilter.m in Sources */, + 84358FFE1DD1FEB600811FC7 /* GPUImageAddBlendFilter.m in Sources */, + 843590561DD1FEB600811FC7 /* GPUImageFilterPipeline.m in Sources */, + 843590F21DD1FEB600811FC7 /* GPUImageSepiaFilter.m in Sources */, + 8435915B1DD1FEB600811FC7 /* rtmp.c in Sources */, + 8435906E1DD1FEB600811FC7 /* GPUImageHarrisCornerDetectionFilter.m in Sources */, + 843590AC1DD1FEB600811FC7 /* GPUImageMissEtikateFilter.m in Sources */, + 84D8B5C21D768B6E00752B56 /* LFMP4Atom.m in Sources */, + 8435911C1DD1FEB600811FC7 /* GPUImageThresholdEdgeDetectionFilter.m in Sources */, + 843590A81DD1FEB600811FC7 /* GPUImageMaskFilter.m in Sources */, + 8435900E1DD1FEB600811FC7 /* GPUImageBuffer.m in Sources */, + 843591471DD1FEB600811FC7 /* GPUImageMovieWriter.m in Sources */, + 843590421DD1FEB600811FC7 /* GPUImageDissolveBlendFilter.m in Sources */, + 8435902C1DD1FEB600811FC7 /* GPUImageColourFASTFeatureDetector.m in Sources */, + 843590E61DD1FEB600811FC7 /* GPUImageRGBErosionFilter.m in Sources */, + 843591561DD1FEB600811FC7 /* hashswf.c in Sources */, + 843590301DD1FEB600811FC7 /* GPUImageContrastFilter.m in Sources */, + 843591021DD1FEB600811FC7 /* GPUImageSoftEleganceFilter.m in Sources */, + 84D8B5D21D768B6E00752B56 /* LFLiveVideoConfiguration.m in Sources */, + 84D8B5C61D768B6E00752B56 /* LFVideoEncoder.m in Sources */, + 843590921DD1FEB600811FC7 /* GPUImageLevelsFilter.m in Sources */, + 843591421DD1FEB600811FC7 /* GPUImageZoomBlurFilter.m in Sources */, + 84D8B5D61D768B6E00752B56 /* LFGPUImageEmptyFilter.m in Sources */, + 843590C21DD1FEB600811FC7 /* GPUImageOpacityFilter.m in Sources */, + 843591531DD1FEB600811FC7 /* error.c in Sources */, + 843590EC1DD1FEB600811FC7 /* GPUImageSaturationBlendFilter.m in Sources */, + 8435901C1DD1FEB600811FC7 /* GPUImageColorBlendFilter.m in Sources */, + 843590521DD1FEB600811FC7 /* GPUImageFilter.m in Sources */, + 843590BE1DD1FEB600811FC7 /* GPUImageNonMaximumSuppressionFilter.m in Sources */, + 843590001DD1FEB600811FC7 /* GPUImageAlphaBlendFilter.m in Sources */, + 843590AE1DD1FEB600811FC7 /* GPUImageMonochromeFilter.m in Sources */, + 843591321DD1FEB600811FC7 /* GPUImageUIElement.m in Sources */, + 843591201DD1FEB600811FC7 /* GPUImageThresholdSketchFilter.m in Sources */, + 843590B81DD1FEB600811FC7 /* GPUImageMovieComposition.m in Sources */, + 843590C81DD1FEB600811FC7 /* GPUImageOverlayBlendFilter.m in Sources */, + 843590CE1DD1FEB600811FC7 /* GPUImagePinchDistortionFilter.m in Sources */, + 843590D81DD1FEB600811FC7 /* GPUImagePolkaDotFilter.m in Sources */, + 84358FF81DD1FEB600811FC7 /* GPUImage3x3ConvolutionFilter.m in Sources */, + 8435903A1DD1FEB600811FC7 /* GPUImageDifferenceBlendFilter.m in Sources */, + 843591491DD1FEB600811FC7 /* GPUImagePicture+TextureSubimage.m in Sources */, + 8435909C1DD1FEB600811FC7 /* GPUImageLookupFilter.m in Sources */, + 84D8B5D91D768B6E00752B56 /* LFLiveSession.m in Sources */, + 843590D01DD1FEB600811FC7 /* GPUImagePixellateFilter.m in Sources */, + 843590C41DD1FEB600811FC7 /* GPUImageOpeningFilter.m in Sources */, + 843591081DD1FEB600811FC7 /* GPUImageSolidColorGenerator.m in Sources */, + 843591181DD1FEB600811FC7 /* GPUImageTextureOutput.m in Sources */, + 843590EE1DD1FEB600811FC7 /* GPUImageSaturationFilter.m in Sources */, + 843591141DD1FEB600811FC7 /* GPUImageSwirlFilter.m in Sources */, + 843590BA1DD1FEB600811FC7 /* GPUImageMultiplyBlendFilter.m in Sources */, + 843590A41DD1FEB600811FC7 /* GPUImageLuminosity.m in Sources */, + 84358FFC1DD1FEB600811FC7 /* GPUImageAdaptiveThresholdFilter.m in Sources */, + 843590661DD1FEB600811FC7 /* GPUImageGlassSphereFilter.m in Sources */, + 843591361DD1FEB600811FC7 /* GPUImageVideoCamera.m in Sources */, + 843590581DD1FEB600811FC7 /* GPUImageFourInputFilter.m in Sources */, + 8435912C1DD1FEB600811FC7 /* GPUImageTwoInputFilter.m in Sources */, + 84D8B5E71D768B6E00752B56 /* LFStreamRtmpSocket.m in Sources */, + 843590441DD1FEB600811FC7 /* GPUImageDivideBlendFilter.m in Sources */, + 843590FA1DD1FEB600811FC7 /* GPUImageSketchFilter.m in Sources */, + 843591221DD1FEB600811FC7 /* GPUImageTiltShiftFilter.m in Sources */, + 843590EA1DD1FEB600811FC7 /* GPUImageRGBOpeningFilter.m in Sources */, + 843590E21DD1FEB600811FC7 /* GPUImageRGBClosingFilter.m in Sources */, + 84D8B5D01D768B6E00752B56 /* LFLiveAudioConfiguration.m in Sources */, + 84D8B5CB1D768B6E00752B56 /* LFHardwareAudioEncoder.m in Sources */, + 843590BC1DD1FEB600811FC7 /* GPUImageNobleCornerDetectionFilter.m in Sources */, + 8435907A1DD1FEB600811FC7 /* GPUImageHistogramFilter.m in Sources */, + 84D8B5C91D768B6E00752B56 /* LFH264VideoEncoder.mm in Sources */, + 843590701DD1FEB600811FC7 /* GPUImageHazeFilter.m in Sources */, + 8435908E1DD1FEB600811FC7 /* GPUImageLanczosResamplingFilter.m in Sources */, + 8435901E1DD1FEB600811FC7 /* GPUImageColorBurnBlendFilter.m in Sources */, + 843590C61DD1FEB600811FC7 /* GPUImageOutput.m in Sources */, + 843590E01DD1FEB600811FC7 /* GPUImageRawDataOutput.m in Sources */, + 843590201DD1FEB600811FC7 /* GPUImageColorConversion.m in Sources */, + 84D8B5E51D768B6E00752B56 /* LFStreamingBuffer.m in Sources */, + 8435914E1DD1FEB600811FC7 /* amf.c in Sources */, + 843591301DD1FEB600811FC7 /* GPUImageTwoPassTextureSamplingFilter.m in Sources */, + 843590DE1DD1FEB600811FC7 /* GPUImageRawDataInput.m in Sources */, + 8435911E1DD1FEB600811FC7 /* GPUImageThresholdedNonMaximumSuppressionFilter.m in Sources */, + 8435903E1DD1FEB600811FC7 /* GPUImageDirectionalNonMaximumSuppressionFilter.m in Sources */, + 84D8B5CD1D768B6E00752B56 /* LFHardwareVideoEncoder.m in Sources */, + 8435907C1DD1FEB600811FC7 /* GPUImageHistogramGenerator.m in Sources */, + 8435913C1DD1FEB600811FC7 /* GPUImageWeakPixelInclusionFilter.m in Sources */, + 843590401DD1FEB600811FC7 /* GPUImageDirectionalSobelEdgeDetectionFilter.m in Sources */, + 843590681DD1FEB600811FC7 /* GPUImageGrayscaleFilter.m in Sources */, + 843590461DD1FEB600811FC7 /* GPUImageEmbossFilter.m in Sources */, + 843590781DD1FEB600811FC7 /* GPUImageHistogramEqualizationFilter.m in Sources */, + 843590181DD1FEB600811FC7 /* GPUImageChromaKeyFilter.m in Sources */, + 8435907E1DD1FEB600811FC7 /* GPUImageHoughTransformLineDetector.m in Sources */, + 8435904E1DD1FEB600811FC7 /* GPUImageFalseColorFilter.m in Sources */, + 843591241DD1FEB600811FC7 /* GPUImageToneCurveFilter.m in Sources */, + 8435914D1DD1FEB600811FC7 /* GPUImageView.m in Sources */, + 843591161DD1FEB600811FC7 /* GPUImageTextureInput.m in Sources */, + 843590E81DD1FEB600811FC7 /* GPUImageRGBFilter.m in Sources */, + 8435902A1DD1FEB600811FC7 /* GPUImageColorPackingFilter.m in Sources */, + 843590CA1DD1FEB600811FC7 /* GPUImageParallelCoordinateLineTransformFilter.m in Sources */, + 843590B61DD1FEB600811FC7 /* GPUImageMovie.m in Sources */, + 843590941DD1FEB600811FC7 /* GPUImageLightenBlendFilter.m in Sources */, + 84358FF51DD1FEB600811FC7 /* GLProgram.m in Sources */, + 843591401DD1FEB600811FC7 /* GPUImageXYDerivativeFilter.m in Sources */, + 843590C01DD1FEB600811FC7 /* GPUImageNormalBlendFilter.m in Sources */, + 843590081DD1FEB600811FC7 /* GPUImageBilateralFilter.m in Sources */, + 8435905A1DD1FEB600811FC7 /* GPUImageFramebuffer.m in Sources */, + 843590901DD1FEB600811FC7 /* GPUImageLaplacianFilter.m in Sources */, + 8435912E1DD1FEB600811FC7 /* GPUImageTwoPassFilter.m in Sources */, + 843591101DD1FEB600811FC7 /* GPUImageStretchDistortionFilter.m in Sources */, + 843590621DD1FEB600811FC7 /* GPUImageGaussianBlurPositionFilter.m in Sources */, + 843590641DD1FEB600811FC7 /* GPUImageGaussianSelectiveBlurFilter.m in Sources */, + 8435900C1DD1FEB600811FC7 /* GPUImageBrightnessFilter.m in Sources */, + 843590F81DD1FEB600811FC7 /* GPUImageSingleComponentGaussianBlurFilter.m in Sources */, + 843590D41DD1FEB600811FC7 /* GPUImagePoissonBlendFilter.m in Sources */, + 843590A21DD1FEB600811FC7 /* GPUImageLuminanceThresholdFilter.m in Sources */, + 843590881DD1FEB600811FC7 /* GPUImageJFAVoronoiFilter.m in Sources */, + 843590D61DD1FEB600811FC7 /* GPUImagePolarPixellateFilter.m in Sources */, + 8435901A1DD1FEB600811FC7 /* GPUImageClosingFilter.m in Sources */, + 8435909E1DD1FEB600811FC7 /* GPUImageLowPassFilter.m in Sources */, + 843590761DD1FEB600811FC7 /* GPUImageHighPassFilter.m in Sources */, + 843590F41DD1FEB600811FC7 /* GPUImageSharpenFilter.m in Sources */, + 843591121DD1FEB600811FC7 /* GPUImageSubtractBlendFilter.m in Sources */, + 843590101DD1FEB600811FC7 /* GPUImageBulgeDistortionFilter.m in Sources */, + 8435913A1DD1FEB600811FC7 /* GPUImageVoronoiConsumerFilter.m in Sources */, + 8435904C1DD1FEB600811FC7 /* GPUImageExposureFilter.m in Sources */, + 84D8B5E31D768B6E00752B56 /* LFVideoFrame.m in Sources */, + 8435905C1DD1FEB600811FC7 /* GPUImageFramebufferCache.m in Sources */, + 8435910C1DD1FEB600811FC7 /* GPUImageSphereRefractionFilter.m in Sources */, + 843590801DD1FEB600811FC7 /* GPUImageHSBFilter.m in Sources */, + 843591281DD1FEB600811FC7 /* GPUImageTransformFilter.m in Sources */, + 843590821DD1FEB600811FC7 /* GPUImageHueBlendFilter.m in Sources */, + 84D8B5BC1D768B6E00752B56 /* LFAudioCapture.m in Sources */, + 843590741DD1FEB600811FC7 /* GPUImageHighlightShadowTintFilter.m in Sources */, + 8435913E1DD1FEB600811FC7 /* GPUImageWhiteBalanceFilter.m in Sources */, + 843590501DD1FEB600811FC7 /* GPUImageFASTCornerDetectionFilter.m in Sources */, + 843590721DD1FEB600811FC7 /* GPUImageHighlightShadowFilter.m in Sources */, + 843591341DD1FEB600811FC7 /* GPUImageUnsharpMaskFilter.m in Sources */, + 843590961DD1FEB600811FC7 /* GPUImageLinearBurnBlendFilter.m in Sources */, + 843590B41DD1FEB600811FC7 /* GPUImageMotionDetector.m in Sources */, + 843590361DD1FEB600811FC7 /* GPUImageCrosshatchFilter.m in Sources */, + 84D8B5EA1D768B6E00752B56 /* NSMutableArray+LFAdd.m in Sources */, + 843590DC1DD1FEB600811FC7 /* GPUImagePrewittEdgeDetectionFilter.m in Sources */, + 84358FFA1DD1FEB600811FC7 /* GPUImage3x3TextureSamplingFilter.m in Sources */, + 843590A61DD1FEB600811FC7 /* GPUImageLuminosityBlendFilter.m in Sources */, + 8435914B1DD1FEB600811FC7 /* GPUImagePicture.m in Sources */, + 843590861DD1FEB600811FC7 /* GPUImageiOSBlurFilter.m in Sources */, + 843590E41DD1FEB600811FC7 /* GPUImageRGBDilationFilter.m in Sources */, + 843590121DD1FEB600811FC7 /* GPUImageCannyEdgeDetectionFilter.m in Sources */, + 843590041DD1FEB600811FC7 /* GPUImageAverageColor.m in Sources */, + 843590CC1DD1FEB600811FC7 /* GPUImagePerlinNoiseFilter.m in Sources */, + 8435906C1DD1FEB600811FC7 /* GPUImageHardLightBlendFilter.m in Sources */, + 843590321DD1FEB600811FC7 /* GPUImageCropFilter.m in Sources */, + 843590241DD1FEB600811FC7 /* GPUImageColorInvertFilter.m in Sources */, + 843590021DD1FEB600811FC7 /* GPUImageAmatorkaFilter.m in Sources */, + 8435908A1DD1FEB600811FC7 /* GPUImageKuwaharaFilter.m in Sources */, + 843590F01DD1FEB600811FC7 /* GPUImageScreenBlendFilter.m in Sources */, + 8435902E1DD1FEB600811FC7 /* GPUImageColourFASTSamplingOperation.m in Sources */, + 843590B01DD1FEB600811FC7 /* GPUImageMosaicFilter.m in Sources */, + 843590281DD1FEB600811FC7 /* GPUImageColorMatrixFilter.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 84D0037A1DB8FE1800560583 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 8495F66A1DB8F14600542124 /* LFLiveKitFramework */; + targetProxy = 84D003791DB8FE1800560583 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 8495F6711DB8F14600542124 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CODE_SIGN_IDENTITY = ""; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_SEARCH_PATHS = ""; + HEADER_SEARCH_PATHS = ""; + INFOPLIST_FILE = LFLiveKitFramework/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MACH_O_TYPE = mh_dylib; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKit; + PRODUCT_NAME = LFLiveKit; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 8495F6721DB8F14600542124 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CODE_SIGN_IDENTITY = ""; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_SEARCH_PATHS = ""; + HEADER_SEARCH_PATHS = ""; + INFOPLIST_FILE = LFLiveKitFramework/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MACH_O_TYPE = mh_dylib; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKit; + PRODUCT_NAME = LFLiveKit; + SKIP_INSTALL = YES; + }; + name = Release; + }; + 84D003771DB8FE1000560583 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + DEVELOPMENT_TEAM = G497YX6CBT; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 84D003781DB8FE1000560583 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + DEVELOPMENT_TEAM = G497YX6CBT; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; + 84D8B3961D7574D600752B56 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + 84D8B3971D7574D600752B56 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + 84D8B3991D7574D600752B56 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "\"$(SRCROOT)/../samples/LFLiveKitDemo/Pods\"/**", + ); + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LIBRARY_SEARCH_PATHS = "$(inherited)"; + MACH_O_TYPE = mh_dylib; + OTHER_LDFLAGS = ""; + PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKit; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 84D8B39A1D7574D600752B56 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "\"$(SRCROOT)/../samples/LFLiveKitDemo/Pods\"/**", + ); + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LIBRARY_SEARCH_PATHS = "$(inherited)"; + MACH_O_TYPE = mh_dylib; + OTHER_LDFLAGS = ""; + PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKit; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 8495F6701DB8F14600542124 /* Build configuration list for PBXNativeTarget "LFLiveKitFramework" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 8495F6711DB8F14600542124 /* Debug */, + 8495F6721DB8F14600542124 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 84D003761DB8FE1000560583 /* Build configuration list for PBXAggregateTarget "LFLiveKitFramework-universal" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 84D003771DB8FE1000560583 /* Debug */, + 84D003781DB8FE1000560583 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 84D8B38A1D7574D600752B56 /* Build configuration list for PBXProject "LFLiveKit" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 84D8B3961D7574D600752B56 /* Debug */, + 84D8B3971D7574D600752B56 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 84D8B3981D7574D600752B56 /* Build configuration list for PBXNativeTarget "LFLiveKit" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 84D8B3991D7574D600752B56 /* Debug */, + 84D8B39A1D7574D600752B56 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 84D8B3871D7574D600752B56 /* Project object */; +} diff --git a/FrameWork/LFLiveKit.xcodeproj/xcshareddata/xcschemes/LFLiveKit.xcscheme b/FrameWork/LFLiveKit.xcodeproj/xcshareddata/xcschemes/LFLiveKit.xcscheme new file mode 100644 index 00000000..96a517df --- /dev/null +++ b/FrameWork/LFLiveKit.xcodeproj/xcshareddata/xcschemes/LFLiveKit.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FrameWork/LFLiveKit.xcodeproj/xcshareddata/xcschemes/LFLiveKitFramework-universal.xcscheme b/FrameWork/LFLiveKit.xcodeproj/xcshareddata/xcschemes/LFLiveKitFramework-universal.xcscheme new file mode 100644 index 00000000..7b8ea6a4 --- /dev/null +++ b/FrameWork/LFLiveKit.xcodeproj/xcshareddata/xcschemes/LFLiveKitFramework-universal.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FrameWork/LFLiveKit.xcodeproj/xcshareddata/xcschemes/LFLiveKitFramework.xcscheme b/FrameWork/LFLiveKit.xcodeproj/xcshareddata/xcschemes/LFLiveKitFramework.xcscheme new file mode 100644 index 00000000..4993dfe6 --- /dev/null +++ b/FrameWork/LFLiveKit.xcodeproj/xcshareddata/xcschemes/LFLiveKitFramework.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LFLiveKitTests/Info.plist b/FrameWork/LFLiveKitFramework/Info.plist similarity index 81% rename from LFLiveKitTests/Info.plist rename to FrameWork/LFLiveKitFramework/Info.plist index ba72822e..f41f1bd7 100644 --- a/LFLiveKitTests/Info.plist +++ b/FrameWork/LFLiveKitFramework/Info.plist @@ -13,12 +13,12 @@ CFBundleName $(PRODUCT_NAME) CFBundlePackageType - BNDL + FMWK CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? + 2.4.3 CFBundleVersion - 1 + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + diff --git a/FrameWork/LFLiveKitFramework/LFLiveKitFramework.h b/FrameWork/LFLiveKitFramework/LFLiveKitFramework.h new file mode 100644 index 00000000..da6bc789 --- /dev/null +++ b/FrameWork/LFLiveKitFramework/LFLiveKitFramework.h @@ -0,0 +1,26 @@ +// +// LFLiveKitFramework.h +// LFLiveKitFramework +// +// Created by admin on 2016/10/20. +// Copyright © 2016年 admin. All rights reserved. +// + +#import + +//! Project version number for LFLiveKitFramework. +FOUNDATION_EXPORT double LFLiveKitFrameworkVersionNumber; + +//! Project version string for LFLiveKitFramework. +FOUNDATION_EXPORT const unsigned char LFLiveKitFrameworkVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + +#import +#import +#import +#import +#import +#import +#import +#import diff --git a/LFLiveKit.podspec b/LFLiveKit.podspec index efc62471..4153bc8c 100644 --- a/LFLiveKit.podspec +++ b/LFLiveKit.podspec @@ -2,24 +2,19 @@ Pod::Spec.new do |s| s.name = "LFLiveKit" - s.version = "1.6.4" + s.version = "2.6" s.summary = "LaiFeng ios Live. LFLiveKit." s.homepage = "https://github.com/chenliming777" s.license = { :type => "MIT", :file => "LICENSE" } s.author = { "chenliming" => "chenliming777@qq.com" } - s.platform = :ios, "8.0" - s.ios.deployment_target = "8.0" + 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/**/*.{*}" - s.public_header_files = "LFLiveKit/**/*.h" + s.source_files = "LFLiveKit/**/*.{h,m,mm,cpp,c}" + s.public_header_files = ['LFLiveKit/*.h', 'LFLiveKit/objects/*.h', 'LFLiveKit/configuration/*.h'] s.frameworks = "VideoToolbox", "AudioToolbox","AVFoundation","Foundation","UIKit" - s.library = "z" + s.libraries = "c++", "z" s.requires_arc = true - - s.dependency "CocoaAsyncSocket", "~> 7.4.1" - s.dependency 'LMGPUImage', '~> 0.1.9' - s.dependency "pili-librtmp", "~> 1.0.2" - end diff --git a/LFLiveKit.xcodeproj/project.pbxproj b/LFLiveKit.xcodeproj/project.pbxproj deleted file mode 100644 index 95de7bcd..00000000 --- a/LFLiveKit.xcodeproj/project.pbxproj +++ /dev/null @@ -1,756 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 84001F8E1D0015D10026C63F /* LFLiveKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001F8D1D0015D10026C63F /* LFLiveKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 84001F951D0015D10026C63F /* LFLiveKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84001F8A1D0015D10026C63F /* LFLiveKit.framework */; }; - 84001F9A1D0015D10026C63F /* LFLiveKitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001F991D0015D10026C63F /* LFLiveKitTests.m */; }; - 84001FD11D0016380026C63F /* LFAudioCapture.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FA51D0016380026C63F /* LFAudioCapture.h */; }; - 84001FD21D0016380026C63F /* LFAudioCapture.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FA61D0016380026C63F /* LFAudioCapture.m */; }; - 84001FD31D0016380026C63F /* LFVideoCapture.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FA71D0016380026C63F /* LFVideoCapture.h */; }; - 84001FD41D0016380026C63F /* LFVideoCapture.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FA81D0016380026C63F /* LFVideoCapture.m */; }; - 84001FD51D0016380026C63F /* LFAudioEncoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FAA1D0016380026C63F /* LFAudioEncoding.h */; }; - 84001FD61D0016380026C63F /* LFHardwareAudioEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FAB1D0016380026C63F /* LFHardwareAudioEncoder.h */; }; - 84001FD71D0016380026C63F /* LFHardwareAudioEncoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FAC1D0016380026C63F /* LFHardwareAudioEncoder.m */; }; - 84001FD81D0016380026C63F /* LFHardwareVideoEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FAD1D0016380026C63F /* LFHardwareVideoEncoder.h */; }; - 84001FD91D0016380026C63F /* LFHardwareVideoEncoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FAE1D0016380026C63F /* LFHardwareVideoEncoder.m */; }; - 84001FDA1D0016380026C63F /* LFVideoEncoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FAF1D0016380026C63F /* LFVideoEncoding.h */; }; - 84001FDB1D0016380026C63F /* LFLiveAudioConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FB11D0016380026C63F /* LFLiveAudioConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 84001FDC1D0016380026C63F /* LFLiveAudioConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FB21D0016380026C63F /* LFLiveAudioConfiguration.m */; }; - 84001FDD1D0016380026C63F /* LFLiveVideoConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FB31D0016380026C63F /* LFLiveVideoConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 84001FDE1D0016380026C63F /* LFLiveVideoConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FB41D0016380026C63F /* LFLiveVideoConfiguration.m */; }; - 84001FDF1D0016380026C63F /* LFGPUImageBeautyFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FB61D0016380026C63F /* LFGPUImageBeautyFilter.h */; }; - 84001FE01D0016380026C63F /* LFGPUImageBeautyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FB71D0016380026C63F /* LFGPUImageBeautyFilter.m */; }; - 84001FE11D0016380026C63F /* LFGPUImageEmptyFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FB81D0016380026C63F /* LFGPUImageEmptyFilter.h */; }; - 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 */; }; - 84001FE61D0016380026C63F /* LFAudioFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FBE1D0016380026C63F /* LFAudioFrame.m */; }; - 84001FE71D0016380026C63F /* LFFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FBF1D0016380026C63F /* LFFrame.h */; }; - 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 */; }; - 84001FEE1D0016380026C63F /* LFVideoFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FC61D0016380026C63F /* LFVideoFrame.m */; }; - 84001FEF1D0016380026C63F /* LFStreamingBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FCA1D0016380026C63F /* LFStreamingBuffer.h */; }; - 84001FF01D0016380026C63F /* LFStreamingBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FCB1D0016380026C63F /* LFStreamingBuffer.m */; }; - 84001FF11D0016380026C63F /* LFStreamRtmpSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FCC1D0016380026C63F /* LFStreamRtmpSocket.h */; }; - 84001FF21D0016380026C63F /* LFStreamRtmpSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FCD1D0016380026C63F /* LFStreamRtmpSocket.m */; }; - 84001FF31D0016380026C63F /* LFStreamSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FCE1D0016380026C63F /* LFStreamSocket.h */; }; - 84001FF41D0016380026C63F /* NSMutableArray+LFAdd.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FCF1D0016380026C63F /* NSMutableArray+LFAdd.h */; }; - 84001FF51D0016380026C63F /* NSMutableArray+LFAdd.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FD01D0016380026C63F /* NSMutableArray+LFAdd.m */; }; - 84001FF71D0017590026C63F /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84001FF61D0017590026C63F /* AVFoundation.framework */; }; - 84001FF91D00175D0026C63F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84001FF81D00175D0026C63F /* Foundation.framework */; }; - 84001FFB1D0017630026C63F /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84001FFA1D0017630026C63F /* UIKit.framework */; }; - 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 */; }; - 840762C51D07BC7D000FD0BF /* LFStreamTcpSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 840762C31D07BC7D000FD0BF /* LFStreamTcpSocket.h */; }; - 840762C61D07BC7D000FD0BF /* LFStreamTcpSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 840762C41D07BC7D000FD0BF /* LFStreamTcpSocket.m */; }; - 840762D61D07BC8B000FD0BF /* amf.c in Sources */ = {isa = PBXBuildFile; fileRef = 840762C91D07BC8B000FD0BF /* amf.c */; }; - 840762D71D07BC8B000FD0BF /* amf.h in Headers */ = {isa = PBXBuildFile; fileRef = 840762CA1D07BC8B000FD0BF /* amf.h */; }; - 840762D81D07BC8B000FD0BF /* avc.c in Sources */ = {isa = PBXBuildFile; fileRef = 840762CB1D07BC8B000FD0BF /* avc.c */; }; - 840762D91D07BC8B000FD0BF /* avc.h in Headers */ = {isa = PBXBuildFile; fileRef = 840762CC1D07BC8B000FD0BF /* avc.h */; }; - 840762DA1D07BC8B000FD0BF /* flv.c in Sources */ = {isa = PBXBuildFile; fileRef = 840762CD1D07BC8B000FD0BF /* flv.c */; }; - 840762DB1D07BC8B000FD0BF /* flv.h in Headers */ = {isa = PBXBuildFile; fileRef = 840762CE1D07BC8B000FD0BF /* flv.h */; }; - 840762DC1D07BC8B000FD0BF /* info.c in Sources */ = {isa = PBXBuildFile; fileRef = 840762CF1D07BC8B000FD0BF /* info.c */; }; - 840762DD1D07BC8B000FD0BF /* info.h in Headers */ = {isa = PBXBuildFile; fileRef = 840762D01D07BC8B000FD0BF /* info.h */; }; - 840762DE1D07BC8B000FD0BF /* types.c in Sources */ = {isa = PBXBuildFile; fileRef = 840762D11D07BC8B000FD0BF /* types.c */; }; - 840762DF1D07BC8B000FD0BF /* types.h in Headers */ = {isa = PBXBuildFile; fileRef = 840762D21D07BC8B000FD0BF /* types.h */; }; - 840762E01D07BC8B000FD0BF /* LFFlvPackage.h in Headers */ = {isa = PBXBuildFile; fileRef = 840762D31D07BC8B000FD0BF /* LFFlvPackage.h */; }; - 840762E11D07BC8B000FD0BF /* LFFlvPackage.m in Sources */ = {isa = PBXBuildFile; fileRef = 840762D41D07BC8B000FD0BF /* LFFlvPackage.m */; }; - 840762E21D07BC8B000FD0BF /* LFStreamPackage.h in Headers */ = {isa = PBXBuildFile; fileRef = 840762D51D07BC8B000FD0BF /* LFStreamPackage.h */; }; - AD7F89B4621A7EFEBEA72D49 /* libPods-LFLiveKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B8CB02D2A92EA1F5A262F154 /* libPods-LFLiveKit.a */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - 84001F961D0015D10026C63F /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 84001F811D0015D10026C63F /* Project object */; - proxyType = 1; - remoteGlobalIDString = 84001F891D0015D10026C63F; - remoteInfo = LFLiveKit; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXFileReference section */ - 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 = ""; }; - 84001F941D0015D10026C63F /* LFLiveKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LFLiveKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 84001F991D0015D10026C63F /* LFLiveKitTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LFLiveKitTests.m; sourceTree = ""; }; - 84001F9B1D0015D10026C63F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 84001FA51D0016380026C63F /* LFAudioCapture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFAudioCapture.h; sourceTree = ""; }; - 84001FA61D0016380026C63F /* LFAudioCapture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFAudioCapture.m; sourceTree = ""; }; - 84001FA71D0016380026C63F /* LFVideoCapture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFVideoCapture.h; sourceTree = ""; }; - 84001FA81D0016380026C63F /* LFVideoCapture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFVideoCapture.m; sourceTree = ""; }; - 84001FAA1D0016380026C63F /* LFAudioEncoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFAudioEncoding.h; sourceTree = ""; }; - 84001FAB1D0016380026C63F /* LFHardwareAudioEncoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFHardwareAudioEncoder.h; sourceTree = ""; }; - 84001FAC1D0016380026C63F /* LFHardwareAudioEncoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFHardwareAudioEncoder.m; sourceTree = ""; }; - 84001FAD1D0016380026C63F /* LFHardwareVideoEncoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFHardwareVideoEncoder.h; sourceTree = ""; }; - 84001FAE1D0016380026C63F /* LFHardwareVideoEncoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFHardwareVideoEncoder.m; sourceTree = ""; }; - 84001FAF1D0016380026C63F /* LFVideoEncoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFVideoEncoding.h; sourceTree = ""; }; - 84001FB11D0016380026C63F /* LFLiveAudioConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFLiveAudioConfiguration.h; sourceTree = ""; }; - 84001FB21D0016380026C63F /* LFLiveAudioConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFLiveAudioConfiguration.m; sourceTree = ""; }; - 84001FB31D0016380026C63F /* LFLiveVideoConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFLiveVideoConfiguration.h; sourceTree = ""; }; - 84001FB41D0016380026C63F /* LFLiveVideoConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFLiveVideoConfiguration.m; sourceTree = ""; }; - 84001FB61D0016380026C63F /* LFGPUImageBeautyFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFGPUImageBeautyFilter.h; sourceTree = ""; }; - 84001FB71D0016380026C63F /* LFGPUImageBeautyFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFGPUImageBeautyFilter.m; sourceTree = ""; }; - 84001FB81D0016380026C63F /* LFGPUImageEmptyFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFGPUImageEmptyFilter.h; sourceTree = ""; }; - 84001FB91D0016380026C63F /* LFGPUImageEmptyFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFGPUImageEmptyFilter.m; sourceTree = ""; }; - 84001FBA1D0016380026C63F /* LFLiveSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFLiveSession.h; sourceTree = ""; }; - 84001FBB1D0016380026C63F /* LFLiveSession.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFLiveSession.m; sourceTree = ""; }; - 84001FBD1D0016380026C63F /* LFAudioFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFAudioFrame.h; sourceTree = ""; }; - 84001FBE1D0016380026C63F /* LFAudioFrame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFAudioFrame.m; sourceTree = ""; }; - 84001FBF1D0016380026C63F /* LFFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFFrame.h; sourceTree = ""; }; - 84001FC01D0016380026C63F /* LFFrame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFFrame.m; sourceTree = ""; }; - 84001FC11D0016380026C63F /* LFLiveDebug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFLiveDebug.h; sourceTree = ""; }; - 84001FC21D0016380026C63F /* LFLiveDebug.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFLiveDebug.m; sourceTree = ""; }; - 84001FC31D0016380026C63F /* LFLiveStreamInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFLiveStreamInfo.h; sourceTree = ""; }; - 84001FC41D0016380026C63F /* LFLiveStreamInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFLiveStreamInfo.m; sourceTree = ""; }; - 84001FC51D0016380026C63F /* LFVideoFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFVideoFrame.h; sourceTree = ""; }; - 84001FC61D0016380026C63F /* LFVideoFrame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFVideoFrame.m; sourceTree = ""; }; - 84001FCA1D0016380026C63F /* LFStreamingBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFStreamingBuffer.h; sourceTree = ""; }; - 84001FCB1D0016380026C63F /* LFStreamingBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFStreamingBuffer.m; sourceTree = ""; }; - 84001FCC1D0016380026C63F /* LFStreamRtmpSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFStreamRtmpSocket.h; sourceTree = ""; }; - 84001FCD1D0016380026C63F /* LFStreamRtmpSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFStreamRtmpSocket.m; sourceTree = ""; }; - 84001FCE1D0016380026C63F /* LFStreamSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFStreamSocket.h; sourceTree = ""; }; - 84001FCF1D0016380026C63F /* NSMutableArray+LFAdd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableArray+LFAdd.h"; sourceTree = ""; }; - 84001FD01D0016380026C63F /* NSMutableArray+LFAdd.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMutableArray+LFAdd.m"; sourceTree = ""; }; - 84001FF61D0017590026C63F /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; - 84001FF81D00175D0026C63F /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; - 84001FFA1D0017630026C63F /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; - 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; }; - 840762C31D07BC7D000FD0BF /* LFStreamTcpSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFStreamTcpSocket.h; sourceTree = ""; }; - 840762C41D07BC7D000FD0BF /* LFStreamTcpSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFStreamTcpSocket.m; sourceTree = ""; }; - 840762C91D07BC8B000FD0BF /* amf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = amf.c; sourceTree = ""; }; - 840762CA1D07BC8B000FD0BF /* amf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = amf.h; sourceTree = ""; }; - 840762CB1D07BC8B000FD0BF /* avc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = avc.c; sourceTree = ""; }; - 840762CC1D07BC8B000FD0BF /* avc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = avc.h; sourceTree = ""; }; - 840762CD1D07BC8B000FD0BF /* flv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = flv.c; sourceTree = ""; }; - 840762CE1D07BC8B000FD0BF /* flv.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = flv.h; sourceTree = ""; }; - 840762CF1D07BC8B000FD0BF /* info.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = info.c; sourceTree = ""; }; - 840762D01D07BC8B000FD0BF /* info.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = info.h; sourceTree = ""; }; - 840762D11D07BC8B000FD0BF /* types.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = types.c; sourceTree = ""; }; - 840762D21D07BC8B000FD0BF /* types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = types.h; sourceTree = ""; }; - 840762D31D07BC8B000FD0BF /* LFFlvPackage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFFlvPackage.h; sourceTree = ""; }; - 840762D41D07BC8B000FD0BF /* LFFlvPackage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFFlvPackage.m; sourceTree = ""; }; - 840762D51D07BC8B000FD0BF /* LFStreamPackage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFStreamPackage.h; sourceTree = ""; }; - 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 = ""; }; - 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; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 84001F861D0015D10026C63F /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 840020011D0017850026C63F /* libz.tbd in Frameworks */, - 84001FFF1D00176C0026C63F /* VideoToolbox.framework in Frameworks */, - 84001FFD1D0017680026C63F /* AudioToolbox.framework in Frameworks */, - 84001FFB1D0017630026C63F /* UIKit.framework in Frameworks */, - 84001FF91D00175D0026C63F /* Foundation.framework in Frameworks */, - 84001FF71D0017590026C63F /* AVFoundation.framework in Frameworks */, - AD7F89B4621A7EFEBEA72D49 /* libPods-LFLiveKit.a in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 84001F911D0015D10026C63F /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 84001F951D0015D10026C63F /* LFLiveKit.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 0C07D14560B9E91EA1B59306 /* Frameworks */ = { - isa = PBXGroup; - children = ( - 840020001D0017850026C63F /* libz.tbd */, - 84001FFE1D00176C0026C63F /* VideoToolbox.framework */, - 84001FFC1D0017680026C63F /* AudioToolbox.framework */, - 84001FFA1D0017630026C63F /* UIKit.framework */, - 84001FF81D00175D0026C63F /* Foundation.framework */, - 84001FF61D0017590026C63F /* AVFoundation.framework */, - B8CB02D2A92EA1F5A262F154 /* libPods-LFLiveKit.a */, - ); - name = Frameworks; - sourceTree = ""; - }; - 84001F801D0015D10026C63F = { - isa = PBXGroup; - children = ( - 84001F8C1D0015D10026C63F /* LFLiveKit */, - 84001F981D0015D10026C63F /* LFLiveKitTests */, - 84001F8B1D0015D10026C63F /* Products */, - EDD4B76A07A6817C79BB4E5C /* Pods */, - 0C07D14560B9E91EA1B59306 /* Frameworks */, - ); - sourceTree = ""; - }; - 84001F8B1D0015D10026C63F /* Products */ = { - isa = PBXGroup; - children = ( - 84001F8A1D0015D10026C63F /* LFLiveKit.framework */, - 84001F941D0015D10026C63F /* LFLiveKitTests.xctest */, - ); - name = Products; - sourceTree = ""; - }; - 84001F8C1D0015D10026C63F /* LFLiveKit */ = { - isa = PBXGroup; - children = ( - 84001F8D1D0015D10026C63F /* LFLiveKit.h */, - 84001FBA1D0016380026C63F /* LFLiveSession.h */, - 84001FBB1D0016380026C63F /* LFLiveSession.m */, - 84001FBC1D0016380026C63F /* objects */, - 84001FB01D0016380026C63F /* configuration */, - 84001FA41D0016380026C63F /* capture */, - 84001FA91D0016380026C63F /* coder */, - 84001FB51D0016380026C63F /* filter */, - 840762C71D07BC8B000FD0BF /* packet */, - 84001FC91D0016380026C63F /* publish */, - 84001F8F1D0015D10026C63F /* Info.plist */, - ); - path = LFLiveKit; - sourceTree = ""; - }; - 84001F981D0015D10026C63F /* LFLiveKitTests */ = { - isa = PBXGroup; - children = ( - 84001F991D0015D10026C63F /* LFLiveKitTests.m */, - 84001F9B1D0015D10026C63F /* Info.plist */, - ); - path = LFLiveKitTests; - sourceTree = ""; - }; - 84001FA41D0016380026C63F /* capture */ = { - isa = PBXGroup; - children = ( - 84001FA51D0016380026C63F /* LFAudioCapture.h */, - 84001FA61D0016380026C63F /* LFAudioCapture.m */, - 84001FA71D0016380026C63F /* LFVideoCapture.h */, - 84001FA81D0016380026C63F /* LFVideoCapture.m */, - ); - path = capture; - sourceTree = ""; - }; - 84001FA91D0016380026C63F /* coder */ = { - isa = PBXGroup; - children = ( - 84001FAA1D0016380026C63F /* LFAudioEncoding.h */, - 84001FAB1D0016380026C63F /* LFHardwareAudioEncoder.h */, - 84001FAC1D0016380026C63F /* LFHardwareAudioEncoder.m */, - 84001FAD1D0016380026C63F /* LFHardwareVideoEncoder.h */, - 84001FAE1D0016380026C63F /* LFHardwareVideoEncoder.m */, - 84001FAF1D0016380026C63F /* LFVideoEncoding.h */, - ); - path = coder; - sourceTree = ""; - }; - 84001FB01D0016380026C63F /* configuration */ = { - isa = PBXGroup; - children = ( - 84001FB11D0016380026C63F /* LFLiveAudioConfiguration.h */, - 84001FB21D0016380026C63F /* LFLiveAudioConfiguration.m */, - 84001FB31D0016380026C63F /* LFLiveVideoConfiguration.h */, - 84001FB41D0016380026C63F /* LFLiveVideoConfiguration.m */, - ); - path = configuration; - sourceTree = ""; - }; - 84001FB51D0016380026C63F /* filter */ = { - isa = PBXGroup; - children = ( - 84001FB61D0016380026C63F /* LFGPUImageBeautyFilter.h */, - 84001FB71D0016380026C63F /* LFGPUImageBeautyFilter.m */, - 84001FB81D0016380026C63F /* LFGPUImageEmptyFilter.h */, - 84001FB91D0016380026C63F /* LFGPUImageEmptyFilter.m */, - ); - path = filter; - sourceTree = ""; - }; - 84001FBC1D0016380026C63F /* objects */ = { - isa = PBXGroup; - children = ( - 84001FBD1D0016380026C63F /* LFAudioFrame.h */, - 84001FBE1D0016380026C63F /* LFAudioFrame.m */, - 84001FBF1D0016380026C63F /* LFFrame.h */, - 84001FC01D0016380026C63F /* LFFrame.m */, - 84001FC11D0016380026C63F /* LFLiveDebug.h */, - 84001FC21D0016380026C63F /* LFLiveDebug.m */, - 84001FC31D0016380026C63F /* LFLiveStreamInfo.h */, - 84001FC41D0016380026C63F /* LFLiveStreamInfo.m */, - 84001FC51D0016380026C63F /* LFVideoFrame.h */, - 84001FC61D0016380026C63F /* LFVideoFrame.m */, - ); - path = objects; - sourceTree = ""; - }; - 84001FC91D0016380026C63F /* publish */ = { - isa = PBXGroup; - children = ( - 84001FCE1D0016380026C63F /* LFStreamSocket.h */, - 84001FCA1D0016380026C63F /* LFStreamingBuffer.h */, - 84001FCB1D0016380026C63F /* LFStreamingBuffer.m */, - 84001FCC1D0016380026C63F /* LFStreamRtmpSocket.h */, - 84001FCD1D0016380026C63F /* LFStreamRtmpSocket.m */, - 840762C31D07BC7D000FD0BF /* LFStreamTcpSocket.h */, - 840762C41D07BC7D000FD0BF /* LFStreamTcpSocket.m */, - 84001FCF1D0016380026C63F /* NSMutableArray+LFAdd.h */, - 84001FD01D0016380026C63F /* NSMutableArray+LFAdd.m */, - ); - name = publish; - path = upload; - sourceTree = ""; - }; - 840762C71D07BC8B000FD0BF /* packet */ = { - isa = PBXGroup; - children = ( - 840762C81D07BC8B000FD0BF /* flv */, - 840762D31D07BC8B000FD0BF /* LFFlvPackage.h */, - 840762D41D07BC8B000FD0BF /* LFFlvPackage.m */, - 840762D51D07BC8B000FD0BF /* LFStreamPackage.h */, - ); - name = packet; - path = LFLiveKit/packet; - sourceTree = SOURCE_ROOT; - }; - 840762C81D07BC8B000FD0BF /* flv */ = { - isa = PBXGroup; - children = ( - 840762C91D07BC8B000FD0BF /* amf.c */, - 840762CA1D07BC8B000FD0BF /* amf.h */, - 840762CB1D07BC8B000FD0BF /* avc.c */, - 840762CC1D07BC8B000FD0BF /* avc.h */, - 840762CD1D07BC8B000FD0BF /* flv.c */, - 840762CE1D07BC8B000FD0BF /* flv.h */, - 840762CF1D07BC8B000FD0BF /* info.c */, - 840762D01D07BC8B000FD0BF /* info.h */, - 840762D11D07BC8B000FD0BF /* types.c */, - 840762D21D07BC8B000FD0BF /* types.h */, - ); - path = flv; - 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 */ - 84001F871D0015D10026C63F /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 840762DD1D07BC8B000FD0BF /* info.h in Headers */, - 84001FDB1D0016380026C63F /* LFLiveAudioConfiguration.h in Headers */, - 840762E01D07BC8B000FD0BF /* LFFlvPackage.h in Headers */, - 84001FDD1D0016380026C63F /* LFLiveVideoConfiguration.h in Headers */, - 840762D71D07BC8B000FD0BF /* amf.h in Headers */, - 84001FE31D0016380026C63F /* LFLiveSession.h in Headers */, - 840762C51D07BC7D000FD0BF /* LFStreamTcpSocket.h in Headers */, - 840762DF1D07BC8B000FD0BF /* types.h in Headers */, - 84001FEB1D0016380026C63F /* LFLiveStreamInfo.h in Headers */, - 84001FE91D0016380026C63F /* LFLiveDebug.h in Headers */, - 840762E21D07BC8B000FD0BF /* LFStreamPackage.h in Headers */, - 840762DB1D07BC8B000FD0BF /* flv.h in Headers */, - 84001FF11D0016380026C63F /* LFStreamRtmpSocket.h in Headers */, - 84001FE71D0016380026C63F /* LFFrame.h in Headers */, - 84001FEF1D0016380026C63F /* LFStreamingBuffer.h in Headers */, - 84001FD61D0016380026C63F /* LFHardwareAudioEncoder.h in Headers */, - 84001FDF1D0016380026C63F /* LFGPUImageBeautyFilter.h in Headers */, - 84001FD31D0016380026C63F /* LFVideoCapture.h in Headers */, - 84001FD11D0016380026C63F /* LFAudioCapture.h in Headers */, - 84001FF41D0016380026C63F /* NSMutableArray+LFAdd.h in Headers */, - 84001FE11D0016380026C63F /* LFGPUImageEmptyFilter.h in Headers */, - 84001FDA1D0016380026C63F /* LFVideoEncoding.h in Headers */, - 84001FE51D0016380026C63F /* LFAudioFrame.h in Headers */, - 84001FED1D0016380026C63F /* LFVideoFrame.h in Headers */, - 84001FD81D0016380026C63F /* LFHardwareVideoEncoder.h in Headers */, - 84001FD51D0016380026C63F /* LFAudioEncoding.h in Headers */, - 840762D91D07BC8B000FD0BF /* avc.h in Headers */, - 84001FF31D0016380026C63F /* LFStreamSocket.h in Headers */, - 84001F8E1D0015D10026C63F /* LFLiveKit.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXHeadersBuildPhase section */ - -/* Begin PBXNativeTarget section */ - 84001F891D0015D10026C63F /* LFLiveKit */ = { - isa = PBXNativeTarget; - buildConfigurationList = 84001F9E1D0015D10026C63F /* Build configuration list for PBXNativeTarget "LFLiveKit" */; - buildPhases = ( - 8EE9401DCA9508E918B7FB68 /* 📦 Check Pods Manifest.lock */, - 84001F851D0015D10026C63F /* Sources */, - 84001F861D0015D10026C63F /* Frameworks */, - 84001F871D0015D10026C63F /* Headers */, - 84001F881D0015D10026C63F /* Resources */, - 817C22141AD3F2EB34365AA3 /* 📦 Copy Pods Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = LFLiveKit; - productName = LFLiveKit; - productReference = 84001F8A1D0015D10026C63F /* LFLiveKit.framework */; - productType = "com.apple.product-type.framework"; - }; - 84001F931D0015D10026C63F /* LFLiveKitTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 84001FA11D0015D10026C63F /* Build configuration list for PBXNativeTarget "LFLiveKitTests" */; - buildPhases = ( - 84001F901D0015D10026C63F /* Sources */, - 84001F911D0015D10026C63F /* Frameworks */, - 84001F921D0015D10026C63F /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 84001F971D0015D10026C63F /* PBXTargetDependency */, - ); - name = LFLiveKitTests; - productName = LFLiveKitTests; - productReference = 84001F941D0015D10026C63F /* LFLiveKitTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 84001F811D0015D10026C63F /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0730; - ORGANIZATIONNAME = admin; - TargetAttributes = { - 84001F891D0015D10026C63F = { - CreatedOnToolsVersion = 7.3; - }; - 84001F931D0015D10026C63F = { - CreatedOnToolsVersion = 7.3; - }; - }; - }; - buildConfigurationList = 84001F841D0015D10026C63F /* Build configuration list for PBXProject "LFLiveKit" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 84001F801D0015D10026C63F; - productRefGroup = 84001F8B1D0015D10026C63F /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 84001F891D0015D10026C63F /* LFLiveKit */, - 84001F931D0015D10026C63F /* LFLiveKitTests */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 84001F881D0015D10026C63F /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 84001F921D0015D10026C63F /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* 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; - }; - 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; - }; -/* End PBXShellScriptBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 84001F851D0015D10026C63F /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 840762DA1D07BC8B000FD0BF /* flv.c in Sources */, - 84001FE21D0016380026C63F /* LFGPUImageEmptyFilter.m in Sources */, - 84001FE41D0016380026C63F /* LFLiveSession.m in Sources */, - 84001FE61D0016380026C63F /* LFAudioFrame.m in Sources */, - 840762DE1D07BC8B000FD0BF /* types.c in Sources */, - 84001FDC1D0016380026C63F /* LFLiveAudioConfiguration.m in Sources */, - 840762D81D07BC8B000FD0BF /* avc.c in Sources */, - 84001FD41D0016380026C63F /* LFVideoCapture.m in Sources */, - 84001FE81D0016380026C63F /* LFFrame.m in Sources */, - 840762D61D07BC8B000FD0BF /* amf.c in Sources */, - 84001FF01D0016380026C63F /* LFStreamingBuffer.m in Sources */, - 84001FF51D0016380026C63F /* NSMutableArray+LFAdd.m in Sources */, - 84001FDE1D0016380026C63F /* LFLiveVideoConfiguration.m in Sources */, - 84001FD21D0016380026C63F /* LFAudioCapture.m in Sources */, - 84001FF21D0016380026C63F /* LFStreamRtmpSocket.m in Sources */, - 840762E11D07BC8B000FD0BF /* LFFlvPackage.m in Sources */, - 84001FD91D0016380026C63F /* LFHardwareVideoEncoder.m in Sources */, - 84001FEC1D0016380026C63F /* LFLiveStreamInfo.m in Sources */, - 84001FEA1D0016380026C63F /* LFLiveDebug.m in Sources */, - 840762DC1D07BC8B000FD0BF /* info.c in Sources */, - 84001FEE1D0016380026C63F /* LFVideoFrame.m in Sources */, - 84001FD71D0016380026C63F /* LFHardwareAudioEncoder.m in Sources */, - 840762C61D07BC7D000FD0BF /* LFStreamTcpSocket.m in Sources */, - 84001FE01D0016380026C63F /* LFGPUImageBeautyFilter.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 84001F901D0015D10026C63F /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 84001F9A1D0015D10026C63F /* LFLiveKitTests.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - 84001F971D0015D10026C63F /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 84001F891D0015D10026C63F /* LFLiveKit */; - targetProxy = 84001F961D0015D10026C63F /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin XCBuildConfiguration section */ - 84001F9C1D0015D10026C63F /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Debug; - }; - 84001F9D1D0015D10026C63F /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; - VALIDATE_PRODUCT = YES; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Release; - }; - 84001F9F1D0015D10026C63F /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = A17586B27CD6843997425CCF /* Pods-LFLiveKit.debug.xcconfig */; - buildSettings = { - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_BITCODE = NO; - INFOPLIST_FILE = LFLiveKit/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKit.LFLiveKit; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - }; - name = Debug; - }; - 84001FA01D0015D10026C63F /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = B75B965E6B94DE4CBCC82EA7 /* Pods-LFLiveKit.release.xcconfig */; - buildSettings = { - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_BITCODE = NO; - INFOPLIST_FILE = LFLiveKit/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKit.LFLiveKit; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - }; - name = Release; - }; - 84001FA21D0015D10026C63F /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - INFOPLIST_FILE = LFLiveKitTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKit.LFLiveKitTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - 84001FA31D0015D10026C63F /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - INFOPLIST_FILE = LFLiveKitTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKit.LFLiveKitTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 84001F841D0015D10026C63F /* Build configuration list for PBXProject "LFLiveKit" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 84001F9C1D0015D10026C63F /* Debug */, - 84001F9D1D0015D10026C63F /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 84001F9E1D0015D10026C63F /* Build configuration list for PBXNativeTarget "LFLiveKit" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 84001F9F1D0015D10026C63F /* Debug */, - 84001FA01D0015D10026C63F /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 84001FA11D0015D10026C63F /* Build configuration list for PBXNativeTarget "LFLiveKitTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 84001FA21D0015D10026C63F /* Debug */, - 84001FA31D0015D10026C63F /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 84001F811D0015D10026C63F /* Project object */; -} diff --git a/LFLiveKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/LFLiveKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 3f412b52..00000000 --- a/LFLiveKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/LFLiveKit.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate b/LFLiveKit.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100644 index 769c914b..00000000 Binary files a/LFLiveKit.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ diff --git a/LFLiveKit.xcodeproj/xcshareddata/xcschemes/LFLiveKit.xcscheme b/LFLiveKit.xcodeproj/xcshareddata/xcschemes/LFLiveKit.xcscheme deleted file mode 100644 index c6fb5b68..00000000 --- a/LFLiveKit.xcodeproj/xcshareddata/xcschemes/LFLiveKit.xcscheme +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/LFLiveKit.xcodeproj/xcuserdata/admin.xcuserdatad/xcschemes/xcschememanagement.plist b/LFLiveKit.xcodeproj/xcuserdata/admin.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index 28561724..00000000 --- a/LFLiveKit.xcodeproj/xcuserdata/admin.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,27 +0,0 @@ - - - - - SchemeUserState - - LFLiveKit.xcscheme_^#shared#^_ - - orderHint - 0 - - - SuppressBuildableAutocreation - - 84001F891D0015D10026C63F - - primary - - - 84001F931D0015D10026C63F - - primary - - - - - diff --git a/LFLiveKit.xcodeproj/xcuserdata/feng.xcuserdatad/xcschemes/xcschememanagement.plist b/LFLiveKit.xcodeproj/xcuserdata/feng.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index 723c7381..00000000 --- a/LFLiveKit.xcodeproj/xcuserdata/feng.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,19 +0,0 @@ - - - - - SuppressBuildableAutocreation - - 84001F891D0015D10026C63F - - primary - - - 84001F931D0015D10026C63F - - primary - - - - - 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 6eb8b39f..00000000 Binary files a/LFLiveKit.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ diff --git a/LFLiveKit.xcworkspace/xcuserdata/admin.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/LFLiveKit.xcworkspace/xcuserdata/admin.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist deleted file mode 100644 index b7de39b8..00000000 --- a/LFLiveKit.xcworkspace/xcuserdata/admin.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/LFLiveKit.xcworkspace/xcuserdata/feng.xcuserdatad/UserInterfaceState.xcuserstate b/LFLiveKit.xcworkspace/xcuserdata/feng.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100644 index a4192931..00000000 Binary files a/LFLiveKit.xcworkspace/xcuserdata/feng.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ diff --git a/LFLiveKit/LFLiveKit.h b/LFLiveKit/LFLiveKit.h index ebac8b72..7f288b7a 100644 --- a/LFLiveKit/LFLiveKit.h +++ b/LFLiveKit/LFLiveKit.h @@ -2,10 +2,13 @@ // LFLiveKit.h // LFLiveKit // -// Created by admin on 16/5/24. -// Copyright © 2016年 admin. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // +#ifndef LFLiveKit_h +#define LFLiveKit_h + #import "LFLiveSession.h" #import "LFLiveAudioConfiguration.h" #import "LFLiveVideoConfiguration.h" @@ -13,3 +16,7 @@ #import "LFFrame.h" #import "LFLiveStreamInfo.h" #import "LFVideoFrame.h" +#import "LFLiveDebug.h" + +#endif + diff --git a/LFLiveKit/LFLiveSession.h b/LFLiveKit/LFLiveSession.h index 4472179f..95985e42 100755 --- a/LFLiveKit/LFLiveSession.h +++ b/LFLiveKit/LFLiveSession.h @@ -2,8 +2,9 @@ // LFLiveSession.h // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import @@ -15,14 +16,27 @@ #import "LFLiveVideoConfiguration.h" #import "LFLiveDebug.h" -typedef void (^ LFRequestComplete)(_Nullable id info,NSError *_Nullable errorMsg); -/// 流类型 -typedef NS_ENUM(NSUInteger, LFLiveType){ - /// rtmp格式 - LFLiveRTMP = 0, - /// tcp 传输flv格式 - LFLiveFLV = 1, + +typedef NS_ENUM(NSInteger,LFLiveCaptureType) { + LFLiveCaptureAudio, //< capture only audio + LFLiveCaptureVideo, //< capture onlt video + LFLiveInputAudio, //< only audio (External input audio) + LFLiveInputVideo, //< only video (External input video) +}; + + +///< 用来控制采集类型(可以内部采集也可以外部传入等各种组合,支持单音频与单视频,外部输入适用于录屏,无人机等外设介入) +typedef NS_ENUM(NSInteger,LFLiveCaptureTypeMask) { + LFLiveCaptureMaskAudio = (1 << LFLiveCaptureAudio), ///< only inner capture audio (no video) + LFLiveCaptureMaskVideo = (1 << LFLiveCaptureVideo), ///< only inner capture video (no audio) + LFLiveInputMaskAudio = (1 << LFLiveInputAudio), ///< only outer input audio (no video) + LFLiveInputMaskVideo = (1 << LFLiveInputVideo), ///< only outer input video (no audio) + LFLiveCaptureMaskAll = (LFLiveCaptureMaskAudio | LFLiveCaptureMaskVideo), ///< inner capture audio and video + LFLiveInputMaskAll = (LFLiveInputMaskAudio | LFLiveInputMaskVideo), ///< outer input audio and video(method see pushVideo and pushAudio) + LFLiveCaptureMaskAudioInputVideo = (LFLiveCaptureMaskAudio | LFLiveInputMaskVideo), ///< inner capture audio and outer input video(method pushVideo and setRunning) + LFLiveCaptureMaskVideoInputAudio = (LFLiveCaptureMaskVideo | LFLiveInputMaskAudio), ///< inner capture video and outer input audio(method pushAudio and setRunning) + LFLiveCaptureDefaultMask = LFLiveCaptureMaskAll ///< default is inner capture audio and video }; @class LFLiveSession; @@ -32,9 +46,9 @@ typedef NS_ENUM(NSUInteger, LFLiveType){ /** live status changed will callback */ - (void)liveSession:(nullable LFLiveSession *)session liveStateDidChange:(LFLiveState)state; /** live debug info callback */ -- (void)liveSession:(nullable LFLiveSession *)session debugInfo:(nullable LFLiveDebug*)debugInfo; +- (void)liveSession:(nullable LFLiveSession *)session debugInfo:(nullable LFLiveDebug *)debugInfo; /** callback socket errorcode */ -- (void)liveSession:(nullable LFLiveSession*)session errorCode:(LFLiveSocketErrorCode)errorCode; +- (void)liveSession:(nullable LFLiveSession *)session errorCode:(LFLiveSocketErrorCode)errorCode; @end @class LFLiveStreamInfo; @@ -46,13 +60,13 @@ typedef NS_ENUM(NSUInteger, LFLiveType){ /// @name Attribute ///============================================================================= /** The delegate of the capture. captureData callback */ -@property (nullable,nonatomic, weak) id delegate; +@property (nullable, nonatomic, weak) id delegate; /** The running control start capture or stop capture*/ @property (nonatomic, assign) BOOL running; /** The preView will show OpenGL ES view*/ -@property (nonatomic, strong,null_resettable) UIView *preView; +@property (nonatomic, strong, null_resettable) UIView *preView; /** The captureDevicePosition control camraPosition ,default front*/ @property (nonatomic, assign) AVCaptureDevicePosition captureDevicePosition; @@ -60,10 +74,10 @@ typedef NS_ENUM(NSUInteger, LFLiveType){ /** The beautyFace control capture shader filter empty or beautiy */ @property (nonatomic, assign) BOOL beautyFace; -/** The beautyLevel control beautyFace Level, default 0.5, between 0.0 ~ 1.0 */ +/** The beautyLevel control beautyFace Level. Default is 0.5, between 0.0 ~ 1.0 */ @property (nonatomic, assign) CGFloat beautyLevel; -/** The brightLevel control brightness Level, default 0.5, between 0.0 ~ 1.0 */ +/** The brightLevel control brightness Level, Default is 0.5, between 0.0 ~ 1.0 */ @property (nonatomic, assign) CGFloat brightLevel; /** The torch control camera zoom scale default 1.0, between 1.0 ~ 3.0 */ @@ -76,22 +90,42 @@ typedef NS_ENUM(NSUInteger, LFLiveType){ @property (nonatomic, assign) BOOL mirror; /** The muted control callbackAudioData,muted will memset 0.*/ -@property (nonatomic,assign) BOOL muted; +@property (nonatomic, assign) BOOL muted; + +/* The adaptiveBitrate control auto adjust bitrate. Default is NO */ +@property (nonatomic, assign) BOOL adaptiveBitrate; /** The stream control upload and package*/ -@property (nullable,nonatomic, strong,readonly) LFLiveStreamInfo * streamInfo; +@property (nullable, nonatomic, strong, readonly) LFLiveStreamInfo *streamInfo; /** The status of the stream .*/ -@property (nonatomic,assign,readonly) LFLiveState state; +@property (nonatomic, assign, readonly) LFLiveState state; + +/** The captureType control inner or outer audio and video .*/ +@property (nonatomic, assign, readonly) LFLiveCaptureTypeMask captureType; /** The showDebugInfo control streamInfo and uploadInfo(1s) *.*/ -@property (nonatomic,assign) BOOL showDebugInfo; +@property (nonatomic, assign) BOOL showDebugInfo; /** The reconnectInterval control reconnect timeInterval(重连间隔) *.*/ -@property (nonatomic,assign) NSUInteger reconnectInterval; +@property (nonatomic, assign) NSUInteger reconnectInterval; /** The reconnectCount control reconnect count (重连次数) *.*/ -@property (nonatomic,assign) NSUInteger reconnectCount; +@property (nonatomic, assign) NSUInteger reconnectCount; + +/*** The warterMarkView control whether the watermark is displayed or not ,if set ni,will remove watermark,otherwise add. + set alpha represent mix.Position relative to outVideoSize. + *.*/ +@property (nonatomic, strong, nullable) UIView *warterMarkView; + +/* The currentImage is videoCapture shot */ +@property (nonatomic, strong,readonly ,nullable) UIImage *currentImage; + +/* The saveLocalVideo is save the local video */ +@property (nonatomic, assign) BOOL saveLocalVideo; + +/* The saveLocalVideoPath is save the local video path */ +@property (nonatomic, strong, nullable) NSURL *saveLocalVideoPath; #pragma mark - Initializer ///============================================================================= @@ -100,18 +134,29 @@ typedef NS_ENUM(NSUInteger, LFLiveType){ - (nullable instancetype)init UNAVAILABLE_ATTRIBUTE; + (nullable instancetype)new UNAVAILABLE_ATTRIBUTE; +/** + The designated initializer. Multiple instances with the same configuration will make the + capture unstable. + */ +- (nullable instancetype)initWithAudioConfiguration:(nullable LFLiveAudioConfiguration *)audioConfiguration videoConfiguration:(nullable LFLiveVideoConfiguration *)videoConfiguration; + /** The designated initializer. Multiple instances with the same configuration will make the capture unstable. */ -- (nullable instancetype)initWithAudioConfiguration:(nullable LFLiveAudioConfiguration*)audioConfiguration videoConfiguration:(nullable LFLiveVideoConfiguration*)videoConfiguration liveType:(LFLiveType)liveType NS_DESIGNATED_INITIALIZER; +- (nullable instancetype)initWithAudioConfiguration:(nullable LFLiveAudioConfiguration *)audioConfiguration videoConfiguration:(nullable LFLiveVideoConfiguration *)videoConfiguration captureType:(LFLiveCaptureTypeMask)captureType NS_DESIGNATED_INITIALIZER; /** The start stream .*/ -- (void)startLive:(nonnull LFLiveStreamInfo*)streamInfo; +- (void)startLive:(nonnull LFLiveStreamInfo *)streamInfo; /** The stop stream .*/ - (void)stopLive; +/** support outer input yuv or rgb video(set LFLiveCaptureTypeMask) .*/ +- (void)pushVideo:(nullable CVPixelBufferRef)pixelBuffer; + +/** support outer input pcm audio(set LFLiveCaptureTypeMask) .*/ +- (void)pushAudio:(nullable NSData*)audioData; @end diff --git a/LFLiveKit/LFLiveSession.m b/LFLiveKit/LFLiveSession.m index 869cf6df..41a7034e 100755 --- a/LFLiveKit/LFLiveSession.m +++ b/LFLiveKit/LFLiveSession.m @@ -2,8 +2,8 @@ // LFLiveSession.m // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFLiveSession.h" @@ -11,22 +11,18 @@ #import "LFAudioCapture.h" #import "LFHardwareVideoEncoder.h" #import "LFHardwareAudioEncoder.h" -#import "LFStreamRtmpSocket.h" -#import "LFStreamTcpSocket.h" +#import "LFH264VideoEncoder.h" +#import "LFStreamRTMPSocket.h" #import "LFLiveStreamInfo.h" #import "LFGPUImageBeautyFilter.h" +#import "LFH264VideoEncoder.h" -#define LFLiveReportKey @"com.youku.liveSessionReport" -@interface LFLiveSession () -{ - dispatch_semaphore_t _lock; -} -///流媒体格式 -@property (nonatomic, assign) LFLiveType liveType; -///音频配置 +@interface LFLiveSession () + +/// 音频配置 @property (nonatomic, strong) LFLiveAudioConfiguration *audioConfiguration; -///视频配置 +/// 视频配置 @property (nonatomic, strong) LFLiveVideoConfiguration *videoConfiguration; /// 声音采集 @property (nonatomic, strong) LFAudioCapture *audioCaptureSource; @@ -39,135 +35,189 @@ @interface LFLiveSession () socket; + #pragma mark -- 内部标识 -/// 上报 -@property (nonatomic, copy) dispatch_block_t reportBlock; -/// debugInfo +/// 调试信息 @property (nonatomic, strong) LFLiveDebug *debugInfo; -/// streamInfo +/// 流信息 @property (nonatomic, strong) LFLiveStreamInfo *streamInfo; -/// uploading +/// 是否开始上传 @property (nonatomic, assign) BOOL uploading; -/// state -@property (nonatomic,assign,readwrite) LFLiveState state; +/// 当前状态 +@property (nonatomic, assign, readwrite) LFLiveState state; +/// 当前直播type +@property (nonatomic, assign, readwrite) LFLiveCaptureTypeMask captureType; +/// 时间戳锁 +@property (nonatomic, strong) dispatch_semaphore_t lock; + @end /**  时间戳 */ #define NOW (CACurrentMediaTime()*1000) +#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) + @interface LFLiveSession () -@property (nonatomic, assign) uint64_t timestamp; -@property (nonatomic, assign) BOOL isFirstFrame; -@property (nonatomic, assign) uint64_t currentTimestamp; +/// 上传相对时间戳 +@property (nonatomic, assign) uint64_t relativeTimestamps; +/// 音视频是否对齐 +@property (nonatomic, assign) BOOL AVAlignment; +/// 当前是否采集到了音频 +@property (nonatomic, assign) BOOL hasCaptureAudio; +/// 当前是否采集到了关键帧 +@property (nonatomic, assign) BOOL hasKeyFrameVideo; @end @implementation LFLiveSession #pragma mark -- LifeCycle -- (instancetype)initWithAudioConfiguration:(LFLiveAudioConfiguration *)audioConfiguration videoConfiguration:(LFLiveVideoConfiguration *)videoConfiguration liveType:(LFLiveType)liveType{ - if(!audioConfiguration || !videoConfiguration) @throw [NSException exceptionWithName:@"LFLiveSession init error" reason:@"audioConfiguration or videoConfiguration is nil " userInfo:nil]; - if(self = [super init]){ +- (instancetype)initWithAudioConfiguration:(nullable LFLiveAudioConfiguration *)audioConfiguration videoConfiguration:(nullable LFLiveVideoConfiguration *)videoConfiguration { + return [self initWithAudioConfiguration:audioConfiguration videoConfiguration:videoConfiguration captureType:LFLiveCaptureDefaultMask]; +} + +- (nullable instancetype)initWithAudioConfiguration:(nullable LFLiveAudioConfiguration *)audioConfiguration videoConfiguration:(nullable LFLiveVideoConfiguration *)videoConfiguration captureType:(LFLiveCaptureTypeMask)captureType{ + if((captureType & LFLiveCaptureMaskAudio || captureType & LFLiveInputMaskAudio) && !audioConfiguration) @throw [NSException exceptionWithName:@"LFLiveSession init error" reason:@"audioConfiguration is nil " userInfo:nil]; + if((captureType & LFLiveCaptureMaskVideo || captureType & LFLiveInputMaskVideo) && !videoConfiguration) @throw [NSException exceptionWithName:@"LFLiveSession init error" reason:@"videoConfiguration is nil " userInfo:nil]; + if (self = [super init]) { _audioConfiguration = audioConfiguration; _videoConfiguration = videoConfiguration; - _liveType = liveType; - _lock = dispatch_semaphore_create(1); + _adaptiveBitrate = NO; + _captureType = captureType; } return self; } -- (void)dealloc{ - self.audioCaptureSource.running = NO; - self.videoCaptureSource.running = NO; +- (void)dealloc { + _videoCaptureSource.running = NO; + _audioCaptureSource.running = NO; } #pragma mark -- CustomMethod -- (void)startLive:(LFLiveStreamInfo*)streamInfo{ - if(!streamInfo) return; +- (void)startLive:(LFLiveStreamInfo *)streamInfo { + if (!streamInfo) return; _streamInfo = streamInfo; _streamInfo.videoConfiguration = _videoConfiguration; _streamInfo.audioConfiguration = _audioConfiguration; [self.socket start]; } -- (void)stopLive{ +- (void)stopLive { self.uploading = NO; [self.socket stop]; + self.socket = nil; +} + +- (void)pushVideo:(nullable CVPixelBufferRef)pixelBuffer{ + if(self.captureType & LFLiveInputMaskVideo){ + if (self.uploading) [self.videoEncoder encodeVideoData:pixelBuffer timeStamp:NOW]; + } +} + +- (void)pushAudio:(nullable NSData*)audioData{ + if(self.captureType & LFLiveInputMaskAudio){ + if (self.uploading) [self.audioEncoder encodeAudioData:audioData timeStamp:NOW]; + } +} + +#pragma mark -- PrivateMethod +- (void)pushSendBuffer:(LFFrame*)frame{ + if(self.relativeTimestamps == 0){ + self.relativeTimestamps = frame.timestamp; + } + frame.timestamp = [self uploadTimestamp:frame.timestamp]; + [self.socket sendFrame:frame]; } #pragma mark -- CaptureDelegate -- (void)captureOutput:(nullable LFAudioCapture*)capture audioBuffer:(AudioBufferList)inBufferList{ - [self.audioEncoder encodeAudioData:inBufferList timeStamp:self.currentTimestamp]; +- (void)captureOutput:(nullable LFAudioCapture *)capture audioData:(nullable NSData*)audioData { + if (self.uploading) [self.audioEncoder encodeAudioData:audioData timeStamp:NOW]; } -- (void)captureOutput:(nullable LFVideoCapture*)capture pixelBuffer:(nullable CVImageBufferRef)pixelBuffer{ - [self.videoEncoder encodeVideoData:pixelBuffer timeStamp:self.currentTimestamp]; +- (void)captureOutput:(nullable LFVideoCapture *)capture pixelBuffer:(nullable CVPixelBufferRef)pixelBuffer { + if (self.uploading) [self.videoEncoder encodeVideoData:pixelBuffer timeStamp:NOW]; } #pragma mark -- EncoderDelegate -- (void)audioEncoder:(nullable id)encoder audioFrame:(nullable LFAudioFrame*)frame{ - if(self.uploading) [self.socket sendFrame:frame];//<上传 +- (void)audioEncoder:(nullable id)encoder audioFrame:(nullable LFAudioFrame *)frame { + //<上传 时间戳对齐 + if (self.uploading){ + self.hasCaptureAudio = YES; + if(self.AVAlignment) [self pushSendBuffer:frame]; + } } -- (void)videoEncoder:(nullable id)encoder videoFrame:(nullable LFVideoFrame*)frame{ - if(self.uploading) [self.socket sendFrame:frame];//<上传 +- (void)videoEncoder:(nullable id)encoder videoFrame:(nullable LFVideoFrame *)frame { + //<上传 时间戳对齐 + if (self.uploading){ + if(frame.isKeyFrame && self.hasCaptureAudio) self.hasKeyFrameVideo = YES; + if(self.AVAlignment) [self pushSendBuffer:frame]; + } } #pragma mark -- LFStreamTcpSocketDelegate -- (void)socketStatus:(nullable id)socket status:(LFLiveState)status{ - if(status == LFLiveStart){ - if(!self.uploading){ - self.timestamp = 0; - self.isFirstFrame = YES; +- (void)socketStatus:(nullable id)socket status:(LFLiveState)status { + if (status == LFLiveStart) { + if (!self.uploading) { + self.AVAlignment = NO; + self.hasCaptureAudio = NO; + self.hasKeyFrameVideo = NO; + self.relativeTimestamps = 0; self.uploading = YES; } + } else if(status == LFLiveStop || status == LFLiveError){ + self.uploading = NO; } dispatch_async(dispatch_get_main_queue(), ^{ self.state = status; - if(self.delegate && [self.delegate respondsToSelector:@selector(liveSession:liveStateDidChange:)]){ + if (self.delegate && [self.delegate respondsToSelector:@selector(liveSession:liveStateDidChange:)]) { [self.delegate liveSession:self liveStateDidChange:status]; } }); } -- (void)socketDidError:(nullable id)socket errorCode:(LFLiveSocketErrorCode)errorCode{ +- (void)socketDidError:(nullable id)socket errorCode:(LFLiveSocketErrorCode)errorCode { dispatch_async(dispatch_get_main_queue(), ^{ - if(self.delegate && [self.delegate respondsToSelector:@selector(liveSession:errorCode:)]){ + if (self.delegate && [self.delegate respondsToSelector:@selector(liveSession:errorCode:)]) { [self.delegate liveSession:self errorCode:errorCode]; } }); } -- (void)socketDebug:(nullable id)socket debugInfo:(nullable LFLiveDebug*)debugInfo{ +- (void)socketDebug:(nullable id)socket debugInfo:(nullable LFLiveDebug *)debugInfo { self.debugInfo = debugInfo; - if(self.showDebugInfo){ + if (self.showDebugInfo) { dispatch_async(dispatch_get_main_queue(), ^{ - if(self.delegate && [self.delegate respondsToSelector:@selector(liveSession:debugInfo:)]){ + if (self.delegate && [self.delegate respondsToSelector:@selector(liveSession:debugInfo:)]) { [self.delegate liveSession:self debugInfo:debugInfo]; } }); } } -- (void)socketBufferStatus:(nullable id)socket status:(LFLiveBuffferState)status{ - NSUInteger videoBitRate = [_videoEncoder videoBitRate]; - if(status == LFLiveBuffferIncrease){ - if(videoBitRate < _videoConfiguration.videoMaxBitRate){ - videoBitRate = videoBitRate + 50 * 1000; - [_videoEncoder setVideoBitRate:videoBitRate]; - } - }else{ - if(videoBitRate > _videoConfiguration.videoMinBitRate){ - videoBitRate = videoBitRate - 100 * 1000; - [_videoEncoder setVideoBitRate:videoBitRate]; +- (void)socketBufferStatus:(nullable id)socket status:(LFLiveBuffferState)status { + if((self.captureType & LFLiveCaptureMaskVideo || self.captureType & LFLiveInputMaskVideo) && self.adaptiveBitrate){ + NSUInteger videoBitRate = [self.videoEncoder videoBitRate]; + if (status == LFLiveBuffferDecline) { + if (videoBitRate < _videoConfiguration.videoMaxBitRate) { + videoBitRate = videoBitRate + 50 * 1000; + [self.videoEncoder setVideoBitRate:videoBitRate]; + NSLog(@"Increase bitrate %@", @(videoBitRate)); + } + } else { + if (videoBitRate > self.videoConfiguration.videoMinBitRate) { + videoBitRate = videoBitRate - 100 * 1000; + [self.videoEncoder setVideoBitRate:videoBitRate]; + NSLog(@"Decline bitrate %@", @(videoBitRate)); + } } } } #pragma mark -- Getter Setter -- (void)setRunning:(BOOL)running{ - if(_running == running) return; +- (void)setRunning:(BOOL)running { + if (_running == running) return; [self willChangeValueForKey:@"running"]; _running = running; [self didChangeValueForKey:@"running"]; @@ -175,32 +225,57 @@ - (void)setRunning:(BOOL)running{ self.audioCaptureSource.running = _running; } -- (void)setPreView:(UIView *)preView{ +- (void)setPreView:(UIView *)preView { + [self willChangeValueForKey:@"preView"]; [self.videoCaptureSource setPreView:preView]; + [self didChangeValueForKey:@"preView"]; } -- (UIView*)preView{ +- (UIView *)preView { return self.videoCaptureSource.preView; } -- (void)setCaptureDevicePosition:(AVCaptureDevicePosition)captureDevicePosition{ +- (void)setCaptureDevicePosition:(AVCaptureDevicePosition)captureDevicePosition { + [self willChangeValueForKey:@"captureDevicePosition"]; [self.videoCaptureSource setCaptureDevicePosition:captureDevicePosition]; + [self didChangeValueForKey:@"captureDevicePosition"]; } -- (AVCaptureDevicePosition)captureDevicePosition{ +- (AVCaptureDevicePosition)captureDevicePosition { return self.videoCaptureSource.captureDevicePosition; } -- (void)setBeautyFace:(BOOL)beautyFace{ +- (void)setBeautyFace:(BOOL)beautyFace { + [self willChangeValueForKey:@"beautyFace"]; [self.videoCaptureSource setBeautyFace:beautyFace]; + [self didChangeValueForKey:@"beautyFace"]; } -- (BOOL)beautyFace{ +- (BOOL)saveLocalVideo{ + return self.videoCaptureSource.saveLocalVideo; +} + +- (void)setSaveLocalVideo:(BOOL)saveLocalVideo{ + [self.videoCaptureSource setSaveLocalVideo:saveLocalVideo]; +} + + +- (NSURL*)saveLocalVideoPath{ + return self.videoCaptureSource.saveLocalVideoPath; +} + +- (void)setSaveLocalVideoPath:(NSURL*)saveLocalVideoPath{ + [self.videoCaptureSource setSaveLocalVideoPath:saveLocalVideoPath]; +} + +- (BOOL)beautyFace { return self.videoCaptureSource.beautyFace; } - (void)setBeautyLevel:(CGFloat)beautyLevel { + [self willChangeValueForKey:@"beautyLevel"]; [self.videoCaptureSource setBeautyLevel:beautyLevel]; + [self didChangeValueForKey:@"beautyLevel"]; } - (CGFloat)beautyLevel { @@ -208,7 +283,9 @@ - (CGFloat)beautyLevel { } - (void)setBrightLevel:(CGFloat)brightLevel { + [self willChangeValueForKey:@"brightLevel"]; [self.videoCaptureSource setBrightLevel:brightLevel]; + [self didChangeValueForKey:@"brightLevel"]; } - (CGFloat)brightLevel { @@ -216,7 +293,9 @@ - (CGFloat)brightLevel { } - (void)setZoomScale:(CGFloat)zoomScale { + [self willChangeValueForKey:@"zoomScale"]; [self.videoCaptureSource setZoomScale:zoomScale]; + [self didChangeValueForKey:@"zoomScale"]; } - (CGFloat)zoomScale { @@ -224,7 +303,9 @@ - (CGFloat)zoomScale { } - (void)setTorch:(BOOL)torch { + [self willChangeValueForKey:@"torch"]; [self.videoCaptureSource setTorch:torch]; + [self didChangeValueForKey:@"torch"]; } - (BOOL)torch { @@ -232,84 +313,116 @@ - (BOOL)torch { } - (void)setMirror:(BOOL)mirror { + [self willChangeValueForKey:@"mirror"]; [self.videoCaptureSource setMirror:mirror]; + [self didChangeValueForKey:@"mirror"]; } - (BOOL)mirror { return self.videoCaptureSource.mirror; } -- (void)setMuted:(BOOL)muted{ +- (void)setMuted:(BOOL)muted { + [self willChangeValueForKey:@"muted"]; [self.audioCaptureSource setMuted:muted]; + [self didChangeValueForKey:@"muted"]; } -- (BOOL)muted{ +- (BOOL)muted { return self.audioCaptureSource.muted; } -- (LFAudioCapture*)audioCaptureSource{ - if(!_audioCaptureSource){ - _audioCaptureSource = [[LFAudioCapture alloc] initWithAudioConfiguration:_audioConfiguration]; - _audioCaptureSource.delegate = self; +- (void)setWarterMarkView:(UIView *)warterMarkView{ + [self.videoCaptureSource setWarterMarkView:warterMarkView]; +} + +- (nullable UIView*)warterMarkView{ + return self.videoCaptureSource.warterMarkView; +} + +- (nullable UIImage *)currentImage{ + return self.videoCaptureSource.currentImage; +} + +- (LFAudioCapture *)audioCaptureSource { + if (!_audioCaptureSource) { + if(self.captureType & LFLiveCaptureMaskAudio){ + _audioCaptureSource = [[LFAudioCapture alloc] initWithAudioConfiguration:_audioConfiguration]; + _audioCaptureSource.delegate = self; + } } return _audioCaptureSource; } -- (LFVideoCapture*)videoCaptureSource{ - if(!_videoCaptureSource){ - _videoCaptureSource = [[LFVideoCapture alloc] initWithVideoConfiguration:_videoConfiguration]; - _videoCaptureSource.delegate = self; +- (LFVideoCapture *)videoCaptureSource { + if (!_videoCaptureSource) { + if(self.captureType & LFLiveCaptureMaskVideo){ + _videoCaptureSource = [[LFVideoCapture alloc] initWithVideoConfiguration:_videoConfiguration]; + _videoCaptureSource.delegate = self; + } } return _videoCaptureSource; } -- (id)audioEncoder{ - if(!_audioEncoder){ +- (id)audioEncoder { + if (!_audioEncoder) { _audioEncoder = [[LFHardwareAudioEncoder alloc] initWithAudioStreamConfiguration:_audioConfiguration]; [_audioEncoder setDelegate:self]; } return _audioEncoder; } -- (id)videoEncoder{ - if(!_videoEncoder){ - _videoEncoder = [[LFHardwareVideoEncoder alloc] initWithVideoStreamConfiguration:_videoConfiguration]; +- (id)videoEncoder { + if (!_videoEncoder) { + if([[UIDevice currentDevice].systemVersion floatValue] < 8.0){ + _videoEncoder = [[LFH264VideoEncoder alloc] initWithVideoStreamConfiguration:_videoConfiguration]; + }else{ + _videoEncoder = [[LFHardwareVideoEncoder alloc] initWithVideoStreamConfiguration:_videoConfiguration]; + } [_videoEncoder setDelegate:self]; } return _videoEncoder; } -- (id)socket{ - if(!_socket){ - if(self.liveType == LFLiveRTMP){ - _socket = [[LFStreamRtmpSocket alloc] initWithStream:self.streamInfo videoSize:self.videoConfiguration.videoSize reconnectInterval:self.reconnectInterval reconnectCount:self.reconnectCount]; - }else if(self.liveType == LFLiveFLV){ - _socket = [[LFStreamTcpSocket alloc] initWithStream:self.streamInfo videoSize:self.videoConfiguration.videoSize reconnectInterval:self.reconnectInterval reconnectCount:self.reconnectCount]; - } +- (id)socket { + if (!_socket) { + _socket = [[LFStreamRTMPSocket alloc] initWithStream:self.streamInfo reconnectInterval:self.reconnectInterval reconnectCount:self.reconnectCount]; [_socket setDelegate:self]; } return _socket; } -- (LFLiveStreamInfo*)streamInfo{ - if(!_streamInfo){ +- (LFLiveStreamInfo *)streamInfo { + if (!_streamInfo) { _streamInfo = [[LFLiveStreamInfo alloc] init]; } return _streamInfo; } -- (uint64_t)currentTimestamp{ - dispatch_semaphore_wait(_lock, DISPATCH_TIME_FOREVER); - uint64_t currentts = 0; - if(_isFirstFrame == true) { - _timestamp = NOW; - _isFirstFrame = false; - currentts = 0; - } else { - currentts = NOW - _timestamp; +- (dispatch_semaphore_t)lock{ + if(!_lock){ + _lock = dispatch_semaphore_create(1); } - dispatch_semaphore_signal(_lock); + return _lock; +} + +- (uint64_t)uploadTimestamp:(uint64_t)captureTimestamp{ + dispatch_semaphore_wait(self.lock, DISPATCH_TIME_FOREVER); + uint64_t currentts = 0; + currentts = captureTimestamp - self.relativeTimestamps; + dispatch_semaphore_signal(self.lock); return currentts; } +- (BOOL)AVAlignment{ + if((self.captureType & LFLiveCaptureMaskAudio || self.captureType & LFLiveInputMaskAudio) && + (self.captureType & LFLiveCaptureMaskVideo || self.captureType & LFLiveInputMaskVideo) + ){ + if(self.hasCaptureAudio && self.hasKeyFrameVideo) return YES; + else return NO; + }else{ + return YES; + } +} + @end 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..22c653b1 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageUIElement.m @@ -0,0 +1,124 @@ +#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]; + [outputFramebuffer disableReferenceCounting]; // Add this line, because GPUImageTwoInputFilter.m frametime updatedMovieFrameOppositeStillImage is YES, but the secondbuffer not lock + + 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 setInputFramebuffer:outputFramebuffer atIndex:textureIndexOfTarget]; // add this line, because the outputFramebuffer is update above + [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.h b/LFLiveKit/capture/LFAudioCapture.h index ecce3748..00b30774 100755 --- a/LFLiveKit/capture/LFAudioCapture.h +++ b/LFLiveKit/capture/LFAudioCapture.h @@ -2,8 +2,8 @@ // LFAudioCapture.h // LFLiveKit // -// Created by 倾慕 on 16/5/1. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import @@ -17,7 +17,7 @@ extern NSString *_Nullable const LFAudioComponentFailedToCreateNotification; @class LFAudioCapture; /** LFAudioCapture callback audioData */ @protocol LFAudioCaptureDelegate -- (void)captureOutput:(nullable LFAudioCapture*)capture audioBuffer:(AudioBufferList)inBufferList; +- (void)captureOutput:(nullable LFAudioCapture *)capture audioData:(nullable NSData*)audioData; @end @@ -29,10 +29,10 @@ extern NSString *_Nullable const LFAudioComponentFailedToCreateNotification; ///============================================================================= /** The delegate of the capture. captureData callback */ -@property (nullable,nonatomic, weak) id delegate; +@property (nullable, nonatomic, weak) id delegate; /** The muted control callbackAudioData,muted will memset 0.*/ -@property (nonatomic,assign) BOOL muted; +@property (nonatomic, assign) BOOL muted; /** The running control start capture or stop capture*/ @property (nonatomic, assign) BOOL running; @@ -45,8 +45,8 @@ extern NSString *_Nullable const LFAudioComponentFailedToCreateNotification; + (nullable instancetype)new UNAVAILABLE_ATTRIBUTE; /** - The designated initializer. Multiple instances with the same configuration will make the - capture unstable. + The designated initializer. Multiple instances with the same configuration will make the + capture unstable. */ - (nullable instancetype)initWithAudioConfiguration:(nullable LFLiveAudioConfiguration *)configuration NS_DESIGNATED_INITIALIZER; diff --git a/LFLiveKit/capture/LFAudioCapture.m b/LFLiveKit/capture/LFAudioCapture.m index 4f297557..bb565fa4 100755 --- a/LFLiveKit/capture/LFAudioCapture.m +++ b/LFLiveKit/capture/LFAudioCapture.m @@ -2,8 +2,8 @@ // LFAudioCapture.m // LFLiveKit // -// Created by 倾慕 on 16/5/1. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFAudioCapture.h" @@ -14,11 +14,11 @@ @interface LFAudioCapture () -@property (nonatomic, assign) AudioComponentInstance componetInstance; -@property (nonatomic, assign) AudioComponent component; -@property (nonatomic, strong) dispatch_queue_t taskQueue; +@property (nonatomic, assign) AudioComponentInstance componetInstance; +@property (nonatomic, assign) AudioComponent component; +@property (nonatomic, strong) dispatch_queue_t taskQueue; @property (nonatomic, assign) BOOL isRunning; -@property (nonatomic, strong) LFLiveAudioConfiguration *configuration; +@property (nonatomic, strong,nullable) LFLiveAudioConfiguration *configuration; @end @@ -32,7 +32,7 @@ - (instancetype)initWithAudioConfiguration:(LFLiveAudioConfiguration *)configura self.taskQueue = dispatch_queue_create("com.youku.Laifeng.audioCapture.Queue", NULL); AVAudioSession *session = [AVAudioSession sharedInstance]; - [session setActive:YES withOptions:kAudioSessionSetActiveFlag_NotifyOthersOnDeactivation error:nil]; + [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(handleRouteChange:) @@ -43,18 +43,9 @@ - (instancetype)initWithAudioConfiguration:(LFLiveAudioConfiguration *)configura name: AVAudioSessionInterruptionNotification object: session]; - NSError *error = nil; - - [session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionMixWithOthers error:nil]; - - [session setMode:AVAudioSessionModeVideoRecording error:&error]; - - if (![session setActive:YES error:&error]) { - [self handleAudioComponentCreationFailure]; - } - AudioComponentDescription acd; acd.componentType = kAudioUnitType_Output; + //acd.componentSubType = kAudioUnitSubType_VoiceProcessingIO; acd.componentSubType = kAudioUnitSubType_RemoteIO; acd.componentManufacturer = kAudioUnitManufacturer_Apple; acd.componentFlags = 0; @@ -96,18 +87,20 @@ - (instancetype)initWithAudioConfiguration:(LFLiveAudioConfiguration *)configura } [session setPreferredSampleRate:_configuration.audioSampleRate error:nil]; - + [session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers error:nil]; + [session setActive:YES withOptions:kAudioSessionSetActiveFlag_NotifyOthersOnDeactivation error:nil]; [session setActive:YES error:nil]; } return self; } -- (void)dealloc{ +- (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; - + dispatch_sync(self.taskQueue, ^{ - if(self.componetInstance){ + if (self.componetInstance) { + self.isRunning = NO; AudioOutputUnitStop(self.componetInstance); AudioComponentInstanceDispose(self.componetInstance); self.componetInstance = nil; @@ -117,17 +110,22 @@ - (void)dealloc{ } #pragma mark -- Setter -- (void)setRunning:(BOOL)running{ - if(_running == running) return; +- (void)setRunning:(BOOL)running { + if (_running == running) return; _running = running; - if(_running){ + if (_running) { dispatch_async(self.taskQueue, ^{ self.isRunning = YES; NSLog(@"MicrophoneSource: startRunning"); + [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers error:nil]; AudioOutputUnitStart(self.componetInstance); }); - }else{ - self.isRunning = NO; + } else { + dispatch_sync(self.taskQueue, ^{ + self.isRunning = NO; + NSLog(@"MicrophoneSource: stopRunning"); + AudioOutputUnitStop(self.componetInstance); + }); } } @@ -141,43 +139,44 @@ - (void)handleAudioComponentCreationFailure { #pragma mark -- NSNotification - (void)handleRouteChange:(NSNotification *)notification { AVAudioSession *session = [ AVAudioSession sharedInstance ]; - NSString* seccReason = @""; - NSInteger reason = [[[notification userInfo] objectForKey:AVAudioSessionRouteChangeReasonKey] integerValue]; + NSString *seccReason = @""; + NSInteger reason = [[[notification userInfo] objectForKey:AVAudioSessionRouteChangeReasonKey] integerValue]; // AVAudioSessionRouteDescription* prevRoute = [[notification userInfo] objectForKey:AVAudioSessionRouteChangePreviousRouteKey]; switch (reason) { - case AVAudioSessionRouteChangeReasonNoSuitableRouteForCategory: - seccReason = @"The route changed because no suitable route is now available for the specified category."; - break; - case AVAudioSessionRouteChangeReasonWakeFromSleep: - seccReason = @"The route changed when the device woke up from sleep."; - break; - case AVAudioSessionRouteChangeReasonOverride: - seccReason = @"The output route was overridden by the app."; - break; - case AVAudioSessionRouteChangeReasonCategoryChange: - seccReason = @"The category of the session object changed."; - break; - case AVAudioSessionRouteChangeReasonOldDeviceUnavailable: - seccReason = @"The previous audio output path is no longer available."; - break; - case AVAudioSessionRouteChangeReasonNewDeviceAvailable: - seccReason = @"A preferred new audio output path is now available."; - break; - case AVAudioSessionRouteChangeReasonUnknown: - default: - seccReason = @"The reason for the change is unknown."; - break; + case AVAudioSessionRouteChangeReasonNoSuitableRouteForCategory: + seccReason = @"The route changed because no suitable route is now available for the specified category."; + break; + case AVAudioSessionRouteChangeReasonWakeFromSleep: + seccReason = @"The route changed when the device woke up from sleep."; + break; + case AVAudioSessionRouteChangeReasonOverride: + seccReason = @"The output route was overridden by the app."; + break; + case AVAudioSessionRouteChangeReasonCategoryChange: + seccReason = @"The category of the session object changed."; + break; + case AVAudioSessionRouteChangeReasonOldDeviceUnavailable: + seccReason = @"The previous audio output path is no longer available."; + break; + case AVAudioSessionRouteChangeReasonNewDeviceAvailable: + seccReason = @"A preferred new audio output path is now available."; + break; + case AVAudioSessionRouteChangeReasonUnknown: + default: + seccReason = @"The reason for the change is unknown."; + break; } - NSLog(@"handleRouteChange reason is %@",seccReason); - AVAudioSessionPortDescription *input = [[session.currentRoute.inputs count]?session.currentRoute.inputs:nil objectAtIndex:0]; + NSLog(@"handleRouteChange reason is %@", seccReason); + + AVAudioSessionPortDescription *input = [[session.currentRoute.inputs count] ? session.currentRoute.inputs : nil objectAtIndex:0]; if (input.portType == AVAudioSessionPortHeadsetMic) { - + } } - (void)handleInterruption:(NSNotification *)notification { NSInteger reason = 0; - NSString* reasonStr = @""; + NSString *reasonStr = @""; if ([notification.name isEqualToString:AVAudioSessionInterruptionNotification]) { //Posted when an audio interruption occurs. reason = [[[notification userInfo] objectForKey:AVAudioSessionInterruptionTypeKey] integerValue]; @@ -189,27 +188,28 @@ - (void)handleInterruption:(NSNotification *)notification { }); } } - + if (reason == AVAudioSessionInterruptionTypeEnded) { reasonStr = @"AVAudioSessionInterruptionTypeEnded"; - NSNumber* seccondReason = [[notification userInfo] objectForKey:AVAudioSessionInterruptionOptionKey] ; + NSNumber *seccondReason = [[notification userInfo] objectForKey:AVAudioSessionInterruptionOptionKey]; switch ([seccondReason integerValue]) { - case AVAudioSessionInterruptionOptionShouldResume: - if (self.isRunning) { - dispatch_async(self.taskQueue, ^{ - NSLog(@"MicrophoneSource: stopRunning"); - AudioOutputUnitStart(self.componetInstance); - }); - } - // Indicates that the audio session is active and immediately ready to be used. Your app can resume the audio operation that was interrupted. - break; - default: - break; + case AVAudioSessionInterruptionOptionShouldResume: + if (self.isRunning) { + dispatch_async(self.taskQueue, ^{ + NSLog(@"MicrophoneSource: startRunning"); + AudioOutputUnitStart(self.componetInstance); + }); + } + // Indicates that the audio session is active and immediately ready to be used. Your app can resume the audio operation that was interrupted. + break; + default: + break; } } - - }; - NSLog(@"handleInterruption: %@ reason %@",[notification name], reasonStr); + + } + ; + NSLog(@"handleInterruption: %@ reason %@", [notification name], reasonStr); } #pragma mark -- CallBack @@ -221,43 +221,34 @@ static OSStatus handleInputBuffer(void *inRefCon, AudioBufferList *ioData) { @autoreleasepool { LFAudioCapture *source = (__bridge LFAudioCapture *)inRefCon; - if(!source) return -1; - + if (!source) return -1; + AudioBuffer buffer; buffer.mData = NULL; buffer.mDataByteSize = 0; buffer.mNumberChannels = 1; - + AudioBufferList buffers; buffers.mNumberBuffers = 1; buffers.mBuffers[0] = buffer; - + OSStatus status = AudioUnitRender(source.componetInstance, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, &buffers); - - if (!source.isRunning) { - dispatch_sync(source.taskQueue, ^{ - NSLog(@"MicrophoneSource: stopRunning"); - AudioOutputUnitStop(source.componetInstance); - }); - - return status; - } - + if (source.muted) { for (int i = 0; i < buffers.mNumberBuffers; i++) { AudioBuffer ab = buffers.mBuffers[i]; memset(ab.mData, 0, ab.mDataByteSize); } } - - if(!status) { - if(source.delegate && [source.delegate respondsToSelector:@selector(captureOutput:audioBuffer:)]){ - [source.delegate captureOutput:source audioBuffer:buffers]; + + if (!status) { + if (source.delegate && [source.delegate respondsToSelector:@selector(captureOutput:audioData:)]) { + [source.delegate captureOutput:source audioData:[NSData dataWithBytes:buffers.mBuffers[0].mData length:buffers.mBuffers[0].mDataByteSize]]; } } return status; diff --git a/LFLiveKit/capture/LFVideoCapture.h b/LFLiveKit/capture/LFVideoCapture.h index 3c29484e..4e719c0e 100755 --- a/LFLiveKit/capture/LFVideoCapture.h +++ b/LFLiveKit/capture/LFVideoCapture.h @@ -2,8 +2,8 @@ // LFVideoCapture.h // LFLiveKit // -// Created by 倾慕 on 16/5/1. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import @@ -13,7 +13,7 @@ @class LFVideoCapture; /** LFVideoCapture callback videoData */ @protocol LFVideoCaptureDelegate -- (void)captureOutput:(nullable LFVideoCapture*)capture pixelBuffer:(nullable CVImageBufferRef)pixelBuffer; +- (void)captureOutput:(nullable LFVideoCapture *)capture pixelBuffer:(nullable CVPixelBufferRef)pixelBuffer; @end @interface LFVideoCapture : NSObject @@ -24,13 +24,13 @@ ///============================================================================= /** The delegate of the capture. captureData callback */ -@property (nullable,nonatomic, weak) id delegate; +@property (nullable, nonatomic, weak) id delegate; /** The running control start capture or stop capture*/ @property (nonatomic, assign) BOOL running; /** The preView will show OpenGL ES view*/ -@property (null_resettable,nonatomic, strong) UIView * preView; +@property (null_resettable, nonatomic, strong) UIView *preView; /** The captureDevicePosition control camraPosition ,default front*/ @property (nonatomic, assign) AVCaptureDevicePosition captureDevicePosition; @@ -56,6 +56,18 @@ /** The videoFrameRate control videoCapture output data count */ @property (nonatomic, assign) NSInteger videoFrameRate; +/*** The warterMarkView control whether the watermark is displayed or not ,if set ni,will remove watermark,otherwise add *.*/ +@property (nonatomic, strong, nullable) UIView *warterMarkView; + +/* The currentImage is videoCapture shot */ +@property (nonatomic, strong, nullable) UIImage *currentImage; + +/* The saveLocalVideo is save the local video */ +@property (nonatomic, assign) BOOL saveLocalVideo; + +/* The saveLocalVideoPath is save the local video path */ +@property (nonatomic, strong, nullable) NSURL *saveLocalVideoPath; + #pragma mark - Initializer ///============================================================================= /// @name Initializer @@ -64,8 +76,8 @@ + (nullable instancetype)new UNAVAILABLE_ATTRIBUTE; /** - The designated initializer. Multiple instances with the same configuration will make the - capture unstable. + The designated initializer. Multiple instances with the same configuration will make the + capture unstable. */ - (nullable instancetype)initWithVideoConfiguration:(nullable LFLiveVideoConfiguration *)configuration NS_DESIGNATED_INITIALIZER; diff --git a/LFLiveKit/capture/LFVideoCapture.m b/LFLiveKit/capture/LFVideoCapture.m index c7661d19..7e42a3f5 100755 --- a/LFLiveKit/capture/LFVideoCapture.m +++ b/LFLiveKit/capture/LFVideoCapture.m @@ -2,24 +2,37 @@ // LFVideoCapture.m // LFLiveKit // -// Created by 倾慕 on 16/5/1. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFVideoCapture.h" -#import "GPUImage.h" #import "LFGPUImageBeautyFilter.h" #import "LFGPUImageEmptyFilter.h" +#if __has_include() +#import +#elif __has_include("GPUImage/GPUImage.h") +#import "GPUImage/GPUImage.h" +#else +#import "GPUImage.h" +#endif + @interface LFVideoCapture () -@property(nonatomic, strong) GPUImageVideoCamera *videoCamera; -@property(nonatomic, weak) LFGPUImageBeautyFilter *beautyFilter; -@property(nonatomic, strong) GPUImageOutput *filter; -@property(nonatomic, strong) GPUImageOutput *output; -@property(nonatomic, strong) GPUImageCropFilter *cropfilter; -@property(nonatomic, strong) GPUImageView *gpuImageView; -@property(nonatomic, strong) LFLiveVideoConfiguration *configuration; +@property (nonatomic, strong) GPUImageVideoCamera *videoCamera; +@property (nonatomic, strong) LFGPUImageBeautyFilter *beautyFilter; +@property (nonatomic, strong) GPUImageOutput *filter; +@property (nonatomic, strong) GPUImageCropFilter *cropfilter; +@property (nonatomic, strong) GPUImageOutput *output; +@property (nonatomic, strong) GPUImageView *gpuImageView; +@property (nonatomic, strong) LFLiveVideoConfiguration *configuration; + +@property (nonatomic, strong) GPUImageAlphaBlendFilter *blendFilter; +@property (nonatomic, strong) GPUImageUIElement *uiElementInput; +@property (nonatomic, strong) UIView *waterMarkContentView; + +@property (nonatomic, strong) GPUImageMovieWriter *movieWriter; @end @@ -30,96 +43,105 @@ @implementation LFVideoCapture @synthesize zoomScale = _zoomScale; #pragma mark -- LifeCycle -- (instancetype)initWithVideoConfiguration:(LFLiveVideoConfiguration *)configuration{ - if(self = [super init]){ +- (instancetype)initWithVideoConfiguration:(LFLiveVideoConfiguration *)configuration { + if (self = [super init]) { _configuration = configuration; - _videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:_configuration.avSessionPreset cameraPosition:AVCaptureDevicePositionFront]; - _videoCamera.outputImageOrientation = _configuration.orientation; - _videoCamera.horizontallyMirrorFrontFacingCamera = NO; - _videoCamera.horizontallyMirrorRearFacingCamera = NO; - _videoCamera.frameRate = (int32_t)_configuration.videoFrameRate; - - _gpuImageView = [[GPUImageView alloc] initWithFrame:[UIScreen mainScreen].bounds]; - [_gpuImageView setFillMode:kGPUImageFillModePreserveAspectRatioAndFill]; - [_gpuImageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; - [_gpuImageView setInputRotation:kGPUImageFlipHorizonal atIndex:0]; - + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterBackground:) name:UIApplicationWillResignActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground:) name:UIApplicationDidBecomeActiveNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarChanged:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil]; self.beautyFace = YES; self.beautyLevel = 0.5; self.brightLevel = 0.5; self.zoomScale = 1.0; + self.mirror = YES; } return self; } -- (void)dealloc{ +- (void)dealloc { [UIApplication sharedApplication].idleTimerDisabled = NO; [[NSNotificationCenter defaultCenter] removeObserver:self]; [_videoCamera stopCameraCapture]; + if(_gpuImageView){ + [_gpuImageView removeFromSuperview]; + _gpuImageView = nil; + } } #pragma mark -- Setter Getter -- (void)setRunning:(BOOL)running{ - if(_running == running) return; + +- (GPUImageVideoCamera *)videoCamera{ + if(!_videoCamera){ + _videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:_configuration.avSessionPreset cameraPosition:AVCaptureDevicePositionFront]; + _videoCamera.outputImageOrientation = _configuration.outputImageOrientation; + _videoCamera.horizontallyMirrorFrontFacingCamera = NO; + _videoCamera.horizontallyMirrorRearFacingCamera = NO; + _videoCamera.frameRate = (int32_t)_configuration.videoFrameRate; + } + return _videoCamera; +} + +- (void)setRunning:(BOOL)running { + if (_running == running) return; _running = running; - if(!_running){ + if (!_running) { [UIApplication sharedApplication].idleTimerDisabled = NO; - [_videoCamera stopCameraCapture]; - }else{ + [self.videoCamera stopCameraCapture]; + if(self.saveLocalVideo) [self.movieWriter finishRecording]; + } else { [UIApplication sharedApplication].idleTimerDisabled = YES; - [_videoCamera startCameraCapture]; + [self reloadFilter]; + [self.videoCamera startCameraCapture]; + if(self.saveLocalVideo) [self.movieWriter startRecording]; } } -- (void)setPreView:(UIView *)preView{ - if(_gpuImageView.superview) [_gpuImageView removeFromSuperview]; - [preView insertSubview:_gpuImageView atIndex:0]; +- (void)setPreView:(UIView *)preView { + if (self.gpuImageView.superview) [self.gpuImageView removeFromSuperview]; + [preView insertSubview:self.gpuImageView atIndex:0]; + self.gpuImageView.frame = CGRectMake(0, 0, preView.frame.size.width, preView.frame.size.height); } -- (UIView*)preView{ - return _gpuImageView.superview; +- (UIView *)preView { + return self.gpuImageView.superview; } -- (void)setCaptureDevicePosition:(AVCaptureDevicePosition)captureDevicePosition{ - [_videoCamera rotateCamera]; - _videoCamera.frameRate = (int32_t)_configuration.videoFrameRate; - if (captureDevicePosition == AVCaptureDevicePositionFront) { - [_gpuImageView setInputRotation:kGPUImageFlipHorizonal atIndex:0]; - } else { - [_gpuImageView setInputRotation:kGPUImageNoRotation atIndex:0]; - } +- (void)setCaptureDevicePosition:(AVCaptureDevicePosition)captureDevicePosition { + if(captureDevicePosition == self.videoCamera.cameraPosition) return; + [self.videoCamera rotateCamera]; + self.videoCamera.frameRate = (int32_t)_configuration.videoFrameRate; + [self reloadMirror]; } -- (AVCaptureDevicePosition)captureDevicePosition{ - return [_videoCamera cameraPosition]; +- (AVCaptureDevicePosition)captureDevicePosition { + return [self.videoCamera cameraPosition]; } -- (void)setVideoFrameRate:(NSInteger)videoFrameRate{ - if(videoFrameRate <= 0) return; - if(videoFrameRate == _videoCamera.frameRate) return; - _videoCamera.frameRate = (uint32_t)videoFrameRate; +- (void)setVideoFrameRate:(NSInteger)videoFrameRate { + if (videoFrameRate <= 0) return; + if (videoFrameRate == self.videoCamera.frameRate) return; + self.videoCamera.frameRate = (uint32_t)videoFrameRate; } -- (NSInteger)videoFrameRate{ - return _videoCamera.frameRate; +- (NSInteger)videoFrameRate { + return self.videoCamera.frameRate; } - (void)setTorch:(BOOL)torch { BOOL ret; - if(!_videoCamera.captureSession) return; - AVCaptureSession* session = (AVCaptureSession*)_videoCamera.captureSession; + if (!self.videoCamera.captureSession) return; + AVCaptureSession *session = (AVCaptureSession *)self.videoCamera.captureSession; [session beginConfiguration]; - if (_videoCamera.inputCamera) { - if (_videoCamera.inputCamera.torchAvailable) { - NSError* err = nil; - if ([_videoCamera.inputCamera lockForConfiguration:&err]) { - [_videoCamera.inputCamera setTorchMode:( torch ? AVCaptureTorchModeOn : AVCaptureTorchModeOff ) ]; - [_videoCamera.inputCamera unlockForConfiguration]; - ret = (_videoCamera.inputCamera.torchMode == AVCaptureTorchModeOn); + if (self.videoCamera.inputCamera) { + if (self.videoCamera.inputCamera.torchAvailable) { + NSError *err = nil; + if ([self.videoCamera.inputCamera lockForConfiguration:&err]) { + [self.videoCamera.inputCamera setTorchMode:(torch ? AVCaptureTorchModeOn : AVCaptureTorchModeOff) ]; + [self.videoCamera.inputCamera unlockForConfiguration]; + ret = (self.videoCamera.inputCamera.torchMode == AVCaptureTorchModeOn); } else { NSLog(@"Error while locking device for torch: %@", err); ret = false; @@ -131,37 +153,45 @@ - (void)setTorch:(BOOL)torch { [session commitConfiguration]; _torch = ret; } + - (BOOL)torch { - return _videoCamera.inputCamera.torchMode; + return self.videoCamera.inputCamera.torchMode; } + - (void)setMirror:(BOOL)mirror { - _videoCamera.horizontallyMirrorFrontFacingCamera = mirror; - _videoCamera.horizontallyMirrorRearFacingCamera = mirror; + _mirror = mirror; } -- (BOOL)mirror { - return _videoCamera.horizontallyMirrorFrontFacingCamera; + +- (void)setBeautyFace:(BOOL)beautyFace{ + _beautyFace = beautyFace; + [self reloadFilter]; } + - (void)setBeautyLevel:(CGFloat)beautyLevel { _beautyLevel = beautyLevel; - if (_beautyFilter) { - [_beautyFilter setBeautyLevel:_beautyLevel]; + if (self.beautyFilter) { + [self.beautyFilter setBeautyLevel:_beautyLevel]; } } + - (CGFloat)beautyLevel { return _beautyLevel; } + - (void)setBrightLevel:(CGFloat)brightLevel { _brightLevel = brightLevel; - if (_beautyFilter) { - [_beautyFilter setBrightLevel:brightLevel]; + if (self.beautyFilter) { + [self.beautyFilter setBrightLevel:brightLevel]; } } + - (CGFloat)brightLevel { return _brightLevel; } + - (void)setZoomScale:(CGFloat)zoomScale { if (self.videoCamera && self.videoCamera.inputCamera) { - AVCaptureDevice* device = (AVCaptureDevice*)self.videoCamera.inputCamera; + AVCaptureDevice *device = (AVCaptureDevice *)self.videoCamera.inputCamera; if ([device lockForConfiguration:nil]) { device.videoZoomFactor = zoomScale; [device unlockForConfiguration]; @@ -174,84 +204,182 @@ - (CGFloat)zoomScale { return _zoomScale; } -- (void)setBeautyFace:(BOOL)beautyFace{ - if(_beautyFace == beautyFace) return; - - _beautyFace = beautyFace; - [_filter removeAllTargets]; - [_cropfilter removeAllTargets]; - [_videoCamera removeAllTargets]; - - if (_beautyFace) { - _output = [[LFGPUImageEmptyFilter alloc] init]; - _filter = [[LFGPUImageBeautyFilter alloc] init]; - _beautyFilter = _filter; - __weak typeof(self) _self = self; - [_output setFrameProcessingCompletionBlock:^(GPUImageOutput *output, CMTime time) { - [_self processVideo:output]; - }]; - } else { - _filter = [[LFGPUImageEmptyFilter alloc] init]; - _beautyFilter = nil; - __weak typeof(self) _self = self; - [_filter setFrameProcessingCompletionBlock:^(GPUImageOutput *output, CMTime time) { - [_self processVideo:output]; - }]; +- (void)setWarterMarkView:(UIView *)warterMarkView{ + if(_warterMarkView && _warterMarkView.superview){ + [_warterMarkView removeFromSuperview]; + _warterMarkView = nil; } - - if (_configuration.isClipVideo) { - if (_configuration.orientation == UIInterfaceOrientationPortrait || _configuration.orientation == UIInterfaceOrientationPortraitUpsideDown){ - _cropfilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0.125, 0, 0.75, 1)]; - } else { - _cropfilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0, 0.125, 1, 0.75)]; - } - [_videoCamera addTarget:_cropfilter]; - [_cropfilter addTarget:_filter]; - } else { - [_videoCamera addTarget:_filter]; + _warterMarkView = warterMarkView; + self.blendFilter.mix = warterMarkView.alpha; + [self.waterMarkContentView addSubview:_warterMarkView]; + [self reloadFilter]; +} + +- (GPUImageUIElement *)uiElementInput{ + if(!_uiElementInput){ + _uiElementInput = [[GPUImageUIElement alloc] initWithView:self.waterMarkContentView]; } - - if (_beautyFace) { - [_filter addTarget:_output]; - [_output addTarget:_gpuImageView]; - } else { - [_filter addTarget:_gpuImageView]; + return _uiElementInput; +} + +- (GPUImageAlphaBlendFilter *)blendFilter{ + if(!_blendFilter){ + _blendFilter = [[GPUImageAlphaBlendFilter alloc] init]; + _blendFilter.mix = 1.0; + [_blendFilter disableSecondFrameCheck]; } - - if (_videoCamera.cameraPosition == AVCaptureDevicePositionFront) { - [_gpuImageView setInputRotation:kGPUImageFlipHorizonal atIndex:0]; - } else { - [_gpuImageView setInputRotation:kGPUImageNoRotation atIndex:0]; + return _blendFilter; +} + +- (UIView *)waterMarkContentView{ + if(!_waterMarkContentView){ + _waterMarkContentView = [UIView new]; + _waterMarkContentView.frame = CGRectMake(0, 0, self.configuration.videoSize.width, self.configuration.videoSize.height); + _waterMarkContentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; } + return _waterMarkContentView; +} + +- (GPUImageView *)gpuImageView{ + if(!_gpuImageView){ + _gpuImageView = [[GPUImageView alloc] initWithFrame:[UIScreen mainScreen].bounds]; + [_gpuImageView setFillMode:kGPUImageFillModePreserveAspectRatioAndFill]; + [_gpuImageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; + } + return _gpuImageView; +} + +-(UIImage *)currentImage{ + if(_filter){ + [_filter useNextFrameForImageCapture]; + return _filter.imageFromCurrentFramebuffer; + } + return nil; +} + +- (GPUImageMovieWriter*)movieWriter{ + if(!_movieWriter){ + _movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:self.saveLocalVideoPath size:self.configuration.videoSize]; + _movieWriter.encodingLiveVideo = YES; + _movieWriter.shouldPassthroughAudio = YES; + self.videoCamera.audioEncodingTarget = self.movieWriter; + } + return _movieWriter; } #pragma mark -- Custom Method -- (void)processVideo:(GPUImageOutput *)output{ +- (void)processVideo:(GPUImageOutput *)output { __weak typeof(self) _self = self; @autoreleasepool { GPUImageFramebuffer *imageFramebuffer = output.framebufferForOutput; CVPixelBufferRef pixelBuffer = [imageFramebuffer pixelBuffer]; - - if(pixelBuffer && _self.delegate && [_self.delegate respondsToSelector:@selector(captureOutput:pixelBuffer:)]){ + if (pixelBuffer && _self.delegate && [_self.delegate respondsToSelector:@selector(captureOutput:pixelBuffer:)]) { [_self.delegate captureOutput:_self pixelBuffer:pixelBuffer]; } + } +} +- (void)reloadFilter{ + [self.filter removeAllTargets]; + [self.blendFilter removeAllTargets]; + [self.uiElementInput removeAllTargets]; + [self.videoCamera removeAllTargets]; + [self.output removeAllTargets]; + [self.cropfilter removeAllTargets]; + + if (self.beautyFace) { + self.output = [[LFGPUImageEmptyFilter alloc] init]; + self.filter = [[LFGPUImageBeautyFilter alloc] init]; + self.beautyFilter = (LFGPUImageBeautyFilter*)self.filter; + } else { + self.output = [[LFGPUImageEmptyFilter alloc] init]; + self.filter = [[LFGPUImageEmptyFilter alloc] init]; + self.beautyFilter = nil; + } + + ///< 调节镜像 + [self reloadMirror]; + + //< 480*640 比例为4:3 强制转换为16:9 + if([self.configuration.avSessionPreset isEqualToString:AVCaptureSessionPreset640x480]){ + CGRect cropRect = self.configuration.landscape ? CGRectMake(0, 0.125, 1, 0.75) : CGRectMake(0.125, 0, 0.75, 1); + self.cropfilter = [[GPUImageCropFilter alloc] initWithCropRegion:cropRect]; + [self.videoCamera addTarget:self.cropfilter]; + [self.cropfilter addTarget:self.filter]; + }else{ + [self.videoCamera addTarget:self.filter]; + } + + //< 添加水印 + if(self.warterMarkView){ + [self.filter addTarget:self.blendFilter]; + [self.uiElementInput addTarget:self.blendFilter]; + [self.blendFilter addTarget:self.gpuImageView]; + if(self.saveLocalVideo) [self.blendFilter addTarget:self.movieWriter]; + [self.filter addTarget:self.output]; + [self.uiElementInput update]; + }else{ + [self.filter addTarget:self.output]; + [self.output addTarget:self.gpuImageView]; + if(self.saveLocalVideo) [self.output addTarget:self.movieWriter]; + } + + [self.filter forceProcessingAtSize:self.configuration.videoSize]; + [self.output forceProcessingAtSize:self.configuration.videoSize]; + [self.blendFilter forceProcessingAtSize:self.configuration.videoSize]; + [self.uiElementInput forceProcessingAtSize:self.configuration.videoSize]; + + + //< 输出数据 + __weak typeof(self) _self = self; + [self.output setFrameProcessingCompletionBlock:^(GPUImageOutput *output, CMTime time) { + [_self processVideo:output]; + }]; + +} + +- (void)reloadMirror{ + if(self.mirror && self.captureDevicePosition == AVCaptureDevicePositionFront){ + self.videoCamera.horizontallyMirrorFrontFacingCamera = YES; + }else{ + self.videoCamera.horizontallyMirrorFrontFacingCamera = NO; } } #pragma mark Notification -- (void)willEnterBackground:(NSNotification*)notification{ +- (void)willEnterBackground:(NSNotification *)notification { [UIApplication sharedApplication].idleTimerDisabled = NO; - [_videoCamera pauseCameraCapture]; + [self.videoCamera pauseCameraCapture]; runSynchronouslyOnVideoProcessingQueue(^{ glFinish(); }); } -- (void)willEnterForeground:(NSNotification*)notification{ - [_videoCamera resumeCameraCapture]; +- (void)willEnterForeground:(NSNotification *)notification { + [self.videoCamera resumeCameraCapture]; [UIApplication sharedApplication].idleTimerDisabled = YES; } +- (void)statusBarChanged:(NSNotification *)notification { + NSLog(@"UIApplicationWillChangeStatusBarOrientationNotification. UserInfo: %@", notification.userInfo); + UIInterfaceOrientation statusBar = [[UIApplication sharedApplication] statusBarOrientation]; + + if(self.configuration.autorotate){ + if (self.configuration.landscape) { + if (statusBar == UIInterfaceOrientationLandscapeLeft) { + self.videoCamera.outputImageOrientation = UIInterfaceOrientationLandscapeRight; + } else if (statusBar == UIInterfaceOrientationLandscapeRight) { + self.videoCamera.outputImageOrientation = UIInterfaceOrientationLandscapeLeft; + } + } else { + if (statusBar == UIInterfaceOrientationPortrait) { + self.videoCamera.outputImageOrientation = UIInterfaceOrientationPortraitUpsideDown; + } else if (statusBar == UIInterfaceOrientationPortraitUpsideDown) { + self.videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait; + } + } + } +} + @end diff --git a/LFLiveKit/coder/H264/LFAVEncoder.h b/LFLiveKit/coder/H264/LFAVEncoder.h new file mode 100755 index 00000000..9e06e370 --- /dev/null +++ b/LFLiveKit/coder/H264/LFAVEncoder.h @@ -0,0 +1,38 @@ +// +// AVEncoder.h +// Encoder Demo +// +// Created by Geraint Davies on 14/01/2013. +// Copyright (c) 2013 GDCL http://www.gdcl.co.uk/license.htm +// + +#import +#import +#import +#import +#import +#import + +#import "LFVideoEncoder.h" +#import "LFMP4Atom.h" + + + +typedef int (^encoder_handler_t)(NSArray *data, CMTimeValue ptsValue); +typedef int (^param_handler_t)(NSData *params); + +@interface LFAVEncoder : NSObject + +@property (atomic) NSUInteger bitrate; + ++ (LFAVEncoder *)encoderForHeight:(int)height andWidth:(int)width bitrate:(int)bitrate; + +- (void)encodeWithBlock:(encoder_handler_t)block onParams:(param_handler_t)paramsHandler; +- (void)encodeFrame:(CMSampleBufferRef)sampleBuffer; +- (NSData *)getConfigData; +- (void)shutdown; + + +@property (readonly, atomic) int bitspersecond; + +@end diff --git a/LFLiveKit/coder/H264/LFAVEncoder.mm b/LFLiveKit/coder/H264/LFAVEncoder.mm new file mode 100755 index 00000000..95467c8e --- /dev/null +++ b/LFLiveKit/coder/H264/LFAVEncoder.mm @@ -0,0 +1,439 @@ +// +// AVEncoder.m +// Encoder Demo +// +// Created by Geraint Davies on 14/01/2013. +// Copyright (c) 2013 GDCL http://www.gdcl.co.uk/license.htm +// + +#import "LFAVEncoder.h" +#import "LFNALUnit.h" + +static void *AVEncoderContext = &AVEncoderContext; + +static unsigned int to_host(unsigned char *p){ + return (p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3]; +} + +#define OUTPUT_FILE_SWITCH_POINT (50 * 1024 * 1024) // 50 MB switch point +#define MAX_FILENAME_INDEX 5 // filenames "capture1.mp4" wraps at capture5.mp4 + + +@interface LFAVEncoder () + +{ + // initial writer, used to obtain SPS/PPS from header + LFVideoEncoder *_headerWriter; + + // main encoder/writer + LFVideoEncoder *_writer; + + // writer output file (input to our extractor) and monitoring + NSFileHandle *_inputFile; + dispatch_queue_t _readQueue; + dispatch_source_t _readSource; + + // index of current file name + BOOL _swapping; + int _currentFile; + int _height; + int _width; + + // param set data + NSData *_avcC; + int _lengthSize; + + // location of mdat + BOOL _foundMDAT; + uint64_t _posMDAT; + int _bytesToNextAtom; + BOOL _needParams; + + // tracking if NALU is next frame + int _prev_nal_idc; + int _prev_nal_type; + // array of NSData comprising a single frame. each data is one nalu with no start code + NSMutableArray *_pendingNALU; + + // FIFO for frame times + NSMutableArray *_times; + + encoder_handler_t _outputBlock; + param_handler_t _paramsBlock; + + // estimate bitrate over first second + int _bitspersecond; + CMTimeValue _firstpts; +} + +@property (atomic) BOOL bitrateChanged; + +@end + +@implementation LFAVEncoder + +@synthesize bitspersecond = _bitspersecond; + ++ (LFAVEncoder *)encoderForHeight:(int)height andWidth:(int)width bitrate:(int)bitrate { + LFAVEncoder *enc = [LFAVEncoder alloc]; + [enc initForHeight:height andWidth:width bitrate:bitrate]; + return enc; +} + +- (NSString *)makeFilename { + NSString *filename = [NSString stringWithFormat:@"capture%d.mp4", _currentFile]; + NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:filename]; + return path; +} + +- (void)initForHeight:(int)height andWidth:(int)width bitrate:(int)bitrate { + _height = height; + _width = width; + _bitrate = bitrate; + NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:@"params.mp4"]; + _headerWriter = [LFVideoEncoder encoderForPath:path Height:height andWidth:width bitrate:(int)self.bitrate]; + _times = [NSMutableArray arrayWithCapacity:10]; + + // swap between 3 filenames + _currentFile = 1; + _writer = [LFVideoEncoder encoderForPath:[self makeFilename] Height:height andWidth:width bitrate:(int)self.bitrate]; + + [self addObserver:self forKeyPath:NSStringFromSelector(@selector(bitrate)) options:0 context:AVEncoderContext]; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath + ofObject:(id)object + change:(NSDictionary *)change + context:(void *)context { + if (context == AVEncoderContext && [keyPath isEqualToString:NSStringFromSelector(@selector(bitrate))]) { + self.bitrateChanged = YES; + } +} + +- (void)encodeWithBlock:(encoder_handler_t)block onParams:(param_handler_t)paramsHandler { + _outputBlock = block; + _paramsBlock = paramsHandler; + _needParams = YES; + _pendingNALU = nil; + _firstpts = -1; + _bitspersecond = 0; +} + +- (BOOL)parseParams:(NSString *)path { + NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:path]; + struct stat s; + fstat([file fileDescriptor], &s); + LFMP4Atom *movie = [LFMP4Atom atomAt:0 size:(int)s.st_size type:(OSType)('file') inFile:file]; + LFMP4Atom *moov = [movie childOfType:(OSType)('moov') startAt:0]; + LFMP4Atom *trak = nil; + if (moov != nil) { + for (;; ) { + trak = [moov nextChild]; + if (trak == nil) { + break; + } + + if (trak.type == (OSType)('trak')) { + LFMP4Atom *tkhd = [trak childOfType:(OSType)('tkhd') startAt:0]; + NSData *verflags = [tkhd readAt:0 size:4]; + unsigned char *p = (unsigned char *)[verflags bytes]; + if (p[3] & 1) { + break; + } else { + tkhd = nil; + } + } + } + } + LFMP4Atom *stsd = nil; + if (trak != nil) { + LFMP4Atom *media = [trak childOfType:(OSType)('mdia') startAt:0]; + if (media != nil) { + LFMP4Atom *minf = [media childOfType:(OSType)('minf') startAt:0]; + if (minf != nil) { + LFMP4Atom *stbl = [minf childOfType:(OSType)('stbl') startAt:0]; + if (stbl != nil) { + stsd = [stbl childOfType:(OSType)('stsd') startAt:0]; + } + } + } + } + if (stsd != nil) { + LFMP4Atom *avc1 = [stsd childOfType:(OSType)('avc1') startAt:8]; + if (avc1 != nil) { + LFMP4Atom *esd = [avc1 childOfType:(OSType)('avcC') startAt:78]; + if (esd != nil) { + // this is the avcC record that we are looking for + _avcC = [esd readAt:0 size:(int)esd.length]; + if (_avcC != nil) { + // extract size of length field + unsigned char *p = (unsigned char *)[_avcC bytes]; + _lengthSize = (p[4] & 3) + 1; + return YES; + } + } + } + } + return NO; +} + +- (void)onParamsCompletion { + // the initial one-frame-only file has been completed + // Extract the avcC structure and then start monitoring the + // main file to extract video from the mdat chunk. + if ([self parseParams:_headerWriter.path]) { + if (_paramsBlock) { + _paramsBlock(_avcC); + } + _headerWriter = nil; + _swapping = NO; + _inputFile = [NSFileHandle fileHandleForReadingAtPath:_writer.path]; + _readQueue = dispatch_queue_create("uk.co.gdcl.avencoder.read", DISPATCH_QUEUE_SERIAL); + + _readSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, [_inputFile fileDescriptor], 0, _readQueue); + dispatch_source_set_event_handler(_readSource, ^{ + [self onFileUpdate]; + }); + dispatch_resume(_readSource); + } +} + +- (void)encodeFrame:(CMSampleBufferRef)sampleBuffer { + CMTime prestime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer); + NSNumber *pts = [NSNumber numberWithLongLong:prestime.value]; + + @synchronized(self){ + if (_needParams) { + // the avcC record is needed for decoding and it's not written to the file until + // completion. We get round that by writing the first frame to two files; the first + // file (containing only one frame) is then finished, so we can extract the avcC record. + // Only when we've got that do we start reading from the main file. + _needParams = NO; + if ([_headerWriter encodeFrame:sampleBuffer]) { + [_headerWriter finishWithCompletionHandler:^{ + [self onParamsCompletion]; + }]; + } + } + } + + @synchronized(_times){ + [_times addObject:pts]; + } + @synchronized(self){ + // switch output files when we reach a size limit + // to avoid runaway storage use. + if (!_swapping) { + struct stat st; + fstat([_inputFile fileDescriptor], &st); + if (st.st_size > OUTPUT_FILE_SWITCH_POINT || self.bitrateChanged) { + self.bitrateChanged = NO; + _swapping = YES; + LFVideoEncoder *oldVideo = _writer; + + // construct a new writer to the next filename + if (++_currentFile > MAX_FILENAME_INDEX) { + _currentFile = 1; + } + //NSLog(@"Swap to file %d", _currentFile); + _writer = [LFVideoEncoder encoderForPath:[self makeFilename] Height:_height andWidth:_width bitrate:(int)self.bitrate]; + + // to do this seamlessly requires a few steps in the right order + // first, suspend the read source + if (_readSource) { + dispatch_source_cancel(_readSource); + // execute the next step as a block on the same queue, to be sure the suspend is done + dispatch_async(_readQueue, ^{ + // finish the file, writing moov, before reading any more from the file + // since we don't yet know where the mdat ends + _readSource = nil; + [oldVideo finishWithCompletionHandler:^{ + [self swapFiles:oldVideo.path]; + }]; + }); + } else { + [self swapFiles:oldVideo.path]; + } + } + } + [_writer encodeFrame:sampleBuffer]; + } +} + +- (void)swapFiles:(NSString *)oldPath { + // save current position + uint64_t pos = [_inputFile offsetInFile]; + + // re-read mdat length + [_inputFile seekToFileOffset:_posMDAT]; + NSData *hdr = [_inputFile readDataOfLength:4]; + unsigned char *p = (unsigned char *)[hdr bytes]; + if (p) { + int lenMDAT = to_host(p); + + // extract nalus from saved position to mdat end + uint64_t posEnd = _posMDAT + lenMDAT; + uint32_t cRead = (uint32_t)(posEnd - pos); + [_inputFile seekToFileOffset:pos]; + [self readAndDeliver:cRead]; + } + + // close and remove file + [_inputFile closeFile]; + _foundMDAT = false; + _bytesToNextAtom = 0; + [[NSFileManager defaultManager] removeItemAtPath:oldPath error:nil]; + + + // open new file and set up dispatch source + _inputFile = [NSFileHandle fileHandleForReadingAtPath:_writer.path]; + _readSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, [_inputFile fileDescriptor], 0, _readQueue); + dispatch_source_set_event_handler(_readSource, ^{ + [self onFileUpdate]; + }); + dispatch_resume(_readSource); + _swapping = NO; +} + +- (void)readAndDeliver:(uint32_t)cReady { + // Identify the individual NALUs and extract them + while (cReady > _lengthSize) { + NSData *lenField = [_inputFile readDataOfLength:_lengthSize]; + cReady -= _lengthSize; + unsigned char *p = (unsigned char *)[lenField bytes]; + unsigned int lenNALU = to_host(p); + + if (lenNALU > cReady) { + // whole NALU not present -- seek back to start of NALU and wait for more + [_inputFile seekToFileOffset:[_inputFile offsetInFile] - 4]; + break; + } + NSData *nalu = [_inputFile readDataOfLength:lenNALU]; + cReady -= lenNALU; + + [self onNALU:nalu]; + } +} + +- (void)onFileUpdate { + // called whenever there is more data to read in the main encoder output file. + struct stat s; + fstat([_inputFile fileDescriptor], &s); + int cReady = (int)(s.st_size - [_inputFile offsetInFile]); + + // locate the mdat atom if needed + while (!_foundMDAT && (cReady > 8)) { + if (_bytesToNextAtom == 0) { + NSData *hdr = [_inputFile readDataOfLength:8]; + cReady -= 8; + unsigned char *p = (unsigned char *)[hdr bytes]; + int lenAtom = to_host(p); + unsigned int nameAtom = to_host(p+4); + if (nameAtom == (unsigned int)('mdat')) { + _foundMDAT = true; + _posMDAT = [_inputFile offsetInFile] - 8; + } else { + _bytesToNextAtom = lenAtom - 8; + } + } + if (_bytesToNextAtom > 0) { + int cThis = cReady < _bytesToNextAtom ? cReady : _bytesToNextAtom; + _bytesToNextAtom -= cThis; + [_inputFile seekToFileOffset:[_inputFile offsetInFile]+cThis]; + cReady -= cThis; + } + } + if (!_foundMDAT) { + return; + } + + // the mdat must be just encoded video. + [self readAndDeliver:cReady]; +} + +- (void)onEncodedFrame { + CMTimeValue pts = 0; + @synchronized(_times){ + if ([_times count] > 0) { + NSNumber *time = _times[0]; + pts = [time longLongValue]; + [_times removeObjectAtIndex:0]; + if (_firstpts < 0) { + _firstpts = pts; + } + if ((pts - _firstpts) < 1) { + int bytes = 0; + for (NSData *data in _pendingNALU) { + bytes += [data length]; + } + _bitspersecond += (bytes * 8); + } + } else { + //NSLog(@"no pts for buffer"); + } + } + if (_outputBlock != nil) { + _outputBlock(_pendingNALU, pts); + } +} + +// combine multiple NALUs into a single frame, and in the process, convert to BSF +// by adding 00 00 01 startcodes before each NALU. +- (void)onNALU:(NSData *)nalu { + unsigned char *pNal = (unsigned char *)[nalu bytes]; + int idc = pNal[0] & 0x60; + int naltype = pNal[0] & 0x1f; + + if (_pendingNALU) { + LFNALUnit nal(pNal, (int)[nalu length]); + + // we have existing data —is this the same frame? + // typically there are a couple of NALUs per frame in iOS encoding. + // This is not general-purpose: it assumes that arbitrary slice ordering is not allowed. + BOOL bNew = NO; + if ((idc != _prev_nal_idc) && ((idc * _prev_nal_idc) == 0)) { + bNew = YES; + } else if ((naltype != _prev_nal_type) && ((naltype == 5) || (_prev_nal_type == 5))) { + bNew = YES; + } else if ((naltype >= 1) && (naltype <= 5)) { + nal.Skip(8); + int first_mb = (int)nal.GetUE(); + if (first_mb == 0) { + bNew = YES; + } + } + if (bNew) { + [self onEncodedFrame]; + _pendingNALU = nil; + } + } + _prev_nal_type = naltype; + _prev_nal_idc = idc; + if (_pendingNALU == nil) { + _pendingNALU = [NSMutableArray arrayWithCapacity:2]; + } + [_pendingNALU addObject:nalu]; +} + +- (NSData *)getConfigData { + return [_avcC copy]; +} + +- (void)shutdown { + @synchronized(self){ + _readSource = nil; + if (_headerWriter) { + [_headerWriter finishWithCompletionHandler:^{ + _headerWriter = nil; + }]; + } + if (_writer) { + [_writer finishWithCompletionHandler:^{ + _writer = nil; + }]; + } + // !! wait for these to finish before returning and delete temp files + } +} + +@end diff --git a/LFLiveKit/coder/H264/LFMP4Atom.h b/LFLiveKit/coder/H264/LFMP4Atom.h new file mode 100755 index 00000000..c991351b --- /dev/null +++ b/LFLiveKit/coder/H264/LFMP4Atom.h @@ -0,0 +1,30 @@ +// +// LFMP4Atom.h +// Encoder Demo +// +// Created by Geraint Davies on 15/01/2013. +// Copyright (c) 2013 GDCL http://www.gdcl.co.uk/license.htm +// + +#import + +@interface LFMP4Atom : NSObject + +{ + NSFileHandle *_file; + int64_t _offset; + int64_t _length; + OSType _type; + int64_t _nextChild; +} +@property OSType type; +@property int64_t length; + ++ (LFMP4Atom *)atomAt:(int64_t)offset size:(int)length type:(OSType)fourcc inFile:(NSFileHandle *)handle; +- (BOOL)init:(int64_t)offset size:(int)length type:(OSType)fourcc inFile:(NSFileHandle *)handle; +- (NSData *)readAt:(int64_t)offset size:(int)length; +- (BOOL)setChildOffset:(int64_t)offset; +- (LFMP4Atom *)nextChild; +- (LFMP4Atom *)childOfType:(OSType)fourcc startAt:(int64_t)offset; + +@end diff --git a/LFLiveKit/coder/H264/LFMP4Atom.m b/LFLiveKit/coder/H264/LFMP4Atom.m new file mode 100755 index 00000000..7edaf48b --- /dev/null +++ b/LFLiveKit/coder/H264/LFMP4Atom.m @@ -0,0 +1,90 @@ +// +// LFMP4Atom.m +// Encoder Demo +// +// Created by Geraint Davies on 15/01/2013. +// Copyright (c) 2013 GDCL http://www.gdcl.co.uk/license.htm +// + +#import "LFMP4Atom.h" + +static unsigned int to_host(unsigned char *p){ + return (p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3]; +} + +@implementation LFMP4Atom + +@synthesize type = _type; +@synthesize length = _length; + ++ (LFMP4Atom *)atomAt:(int64_t)offset size:(int)length type:(OSType)fourcc inFile:(NSFileHandle *)handle { + LFMP4Atom *atom = [LFMP4Atom alloc]; + if (![atom init:offset size:length type:fourcc inFile:handle]) { + return nil; + } + return atom; +} + +- (BOOL)init:(int64_t)offset size:(int)length type:(OSType)fourcc inFile:(NSFileHandle *)handle { + _file = handle; + _offset = offset; + _length = length; + _type = fourcc; + _nextChild = 0; + + return YES; +} + +- (NSData *)readAt:(int64_t)offset size:(int)length { + [_file seekToFileOffset:_offset + offset]; + return [_file readDataOfLength:length]; +} + +- (BOOL)setChildOffset:(int64_t)offset { + _nextChild = offset; + return YES; +} + +- (LFMP4Atom *)nextChild { + if (_nextChild <= (_length - 8)) { + [_file seekToFileOffset:_offset + _nextChild]; + NSData *data = [_file readDataOfLength:8]; + int cHeader = 8; + unsigned char *p = (unsigned char *)[data bytes]; + int64_t len = to_host(p); + OSType fourcc = to_host(p + 4); + if (len == 1) { + // 64-bit extended length + cHeader += 8; + data = [_file readDataOfLength:8]; + p = (unsigned char *)[data bytes]; + len = to_host(p); + len = (len << 32) + to_host(p + 4); + } else if (len == 0) { + // whole remaining parent space + len = _length - _nextChild; + } + if (fourcc == (OSType)('uuid')) { + cHeader += 16; + } + if ((len < 0) || ((len + _nextChild) > _length)) { + return nil; + } + int64_t offset = _nextChild + cHeader; + _nextChild += len; + len -= cHeader; + return [LFMP4Atom atomAt:offset+_offset size:(int)len type:fourcc inFile:_file]; + } + return nil; +} + +- (LFMP4Atom *)childOfType:(OSType)fourcc startAt:(int64_t)offset { + [self setChildOffset:offset]; + LFMP4Atom *child = nil; + do { + child = [self nextChild]; + } while ((child != nil) && (child.type != fourcc)); + return child; +} + +@end diff --git a/LFLiveKit/coder/H264/LFNALUnit.cpp b/LFLiveKit/coder/H264/LFNALUnit.cpp new file mode 100755 index 00000000..27b2fc0f --- /dev/null +++ b/LFLiveKit/coder/H264/LFNALUnit.cpp @@ -0,0 +1,424 @@ + +// +// NALUnit.cpp +// +// Implementation of Basic parsing of H.264 NAL Units +// +// Geraint Davies, March 2004 +// +// Copyright (c) GDCL 2004-2008 http://www.gdcl.co.uk/license.htm + + + +#include "LFNALUnit.h" + + +// --- core NAL Unit implementation ------------------------------ + +LFNALUnit::LFNALUnit() + : m_pStart(NULL), + m_cBytes(0){ +} + +bool +LFNALUnit::GetStartCode(const BYTE *& pBegin, const BYTE *& pStart, int& cRemain){ + // start code is any number of 00 followed by 00 00 01 + // We need to record the first 00 in pBegin and the first byte + // following the startcode in pStart. + // if no start code is found, pStart and cRemain should be unchanged. + + const BYTE *pThis = pStart; + int cBytes = cRemain; + + pBegin = NULL; + while (cBytes >= 4) { + if (pThis[0] == 0) { + // remember first 00 + if (pBegin == NULL) { + pBegin = pThis; + } + if ((pThis[1] == 0) && + (pThis[2] == 1)) { + // point to type byte of NAL unit + pStart = pThis + 3; + cRemain = cBytes - 3; + return true; + } + } else { + pBegin = NULL; + } + cBytes--; + pThis++; + } + return false; +} + +bool +LFNALUnit::Parse(const BYTE *pBuffer, int cSpace, int LengthSize, bool bEnd){ + // if we get the start code but not the whole + // NALU, we can return false but still have the length property valid + m_cBytes = 0; + + ResetBitstream(); + + if (LengthSize > 0) { + m_pStartCodeStart = pBuffer; + + if (LengthSize > cSpace) { + return false; + } + + m_cBytes = 0; + for (int i = 0; i < LengthSize; i++) { + m_cBytes <<= 8; + m_cBytes += *pBuffer++; + } + + if ((m_cBytes+LengthSize) <= cSpace) { + m_pStart = pBuffer; + return true; + } + } else { + // this is not length-delimited: we must look for start codes + const BYTE *pBegin; + if (GetStartCode(pBegin, pBuffer, cSpace)) { + m_pStart = pBuffer; + m_pStartCodeStart = pBegin; + + // either we find another startcode, or we continue to the + // buffer end (if this is the last block of data) + if (GetStartCode(pBegin, pBuffer, cSpace)) { + m_cBytes = int(pBegin - m_pStart); + return true; + } else if (bEnd) { + // current element extends to end of buffer + m_cBytes = cSpace; + return true; + } + } + } + return false; +} + +// bitwise access to data +void +LFNALUnit::ResetBitstream(){ + m_idx = 0; + m_nBits = 0; + m_cZeros = 0; +} + +void +LFNALUnit::Skip(int nBits){ + if (nBits < m_nBits) { + m_nBits -= nBits; + } else { + nBits -= m_nBits; + while (nBits >= 8) { + GetBYTE(); + nBits -= 8; + } + if (nBits) { + m_byte = GetBYTE(); + m_nBits = 8; + + m_nBits -= nBits; + } + } +} + +// get the next byte, removing emulation prevention bytes +BYTE +LFNALUnit::GetBYTE(){ + if (m_idx >= m_cBytes) { + return 0; + } + + BYTE b = m_pStart[m_idx++]; + + // to avoid start-code emulation, a byte 0x03 is inserted + // after any 00 00 pair. Discard that here. + if (b == 0) { + m_cZeros++; + if ((m_idx < m_cBytes) && (m_cZeros == 2) && (m_pStart[m_idx] == 0x03)) { + m_idx++; + m_cZeros = 0; + } + } else { + m_cZeros = 0; + } + return b; +} + +unsigned long +LFNALUnit::GetBit(){ + if (m_nBits == 0) { + m_byte = GetBYTE(); + m_nBits = 8; + } + m_nBits--; + return (m_byte >> m_nBits) & 0x1; +} + +unsigned long +LFNALUnit::GetWord(int nBits){ + unsigned long u = 0; + while (nBits > 0) { + u <<= 1; + u |= GetBit(); + nBits--; + } + return u; +} + +unsigned long +LFNALUnit::GetUE(){ + // Exp-Golomb entropy coding: leading zeros, then a one, then + // the data bits. The number of leading zeros is the number of + // data bits, counting up from that number of 1s as the base. + // That is, if you see + // 0001010 + // You have three leading zeros, so there are three data bits (010) + // counting up from a base of 111: thus 111 + 010 = 1001 = 9 + int cZeros = 0; + while (GetBit() == 0) { + cZeros++; + } + return GetWord(cZeros) + ((1 << cZeros)-1); +} + +long +LFNALUnit::GetSE(){ + // same as UE but signed. + // basically the unsigned numbers are used as codes to indicate signed numbers in pairs + // in increasing value. Thus the encoded values + // 0, 1, 2, 3, 4 + // mean + // 0, 1, -1, 2, -2 etc + + unsigned long UE = GetUE(); + bool bPositive = UE & 1; + long SE = (UE + 1) >> 1; + if (!bPositive) { + SE = -SE; + } + return SE; +} + +// --- sequence params parsing --------------- +LFSeqParamSet::LFSeqParamSet() + : m_cx(0), + m_cy(0), + m_FrameBits(0){ + // SetRect(&m_rcFrame, 0, 0, 0, 0); +} + +void +ScalingList(int size, LFNALUnit *pnalu){ + long lastScale = 8; + long nextScale = 8; + for (int j = 0; j < size; j++) { + if (nextScale != 0) { + long delta = pnalu->GetSE(); + nextScale = (lastScale + delta + 256) %256; + } + int scaling_list_j = (nextScale == 0) ? (int)lastScale : (int)nextScale; + lastScale = scaling_list_j; + } +} + +bool +LFSeqParamSet::Parse(LFNALUnit *pnalu){ + if (pnalu->Type() != LFNALUnit::NAL_Sequence_Params) { + return false; + } + + // with the UE/SE type encoding, we must decode all the values + // to get through to the ones we want + pnalu->ResetBitstream(); + pnalu->Skip(8); // type + m_Profile =(int) pnalu->GetWord(8); + m_Compatibility = (BYTE)pnalu->GetWord(8); + m_Level = (int)pnalu->GetWord(8); + + /*int seq_param_id =*/ pnalu->GetUE(); + + if ((m_Profile == 100) || (m_Profile == 110) || (m_Profile == 122) || (m_Profile == 144)) { + int chroma_fmt = (int)pnalu->GetUE(); + if (chroma_fmt == 3) { + pnalu->Skip(1); + } + /* int bit_depth_luma_minus8 = */ pnalu->GetUE(); + /* int bit_depth_chroma_minus8 = */ pnalu->GetUE(); + pnalu->Skip(1); + int seq_scaling_matrix_present = (int)pnalu->GetBit(); + if (seq_scaling_matrix_present) { + for (int i = 0; i < 8; i++) { + if (pnalu->GetBit()) { + if (i < 6) { + ScalingList(16, pnalu); + } else { + ScalingList(64, pnalu); + } + } + } + } + } + + int log2_frame_minus4 = (int)pnalu->GetUE(); + m_FrameBits = log2_frame_minus4 + 4; + int POCtype = (int)pnalu->GetUE(); + if (POCtype == 0) { + /*int log2_poc_minus4 =*/ pnalu->GetUE(); + } else if (POCtype == 1) { + pnalu->Skip(1); // delta always zero + /*int nsp_offset =*/ pnalu->GetSE(); + /*int nsp_top_to_bottom = */ pnalu->GetSE(); + int num_ref_in_cycle = (int)pnalu->GetUE(); + for (int i = 0; i < num_ref_in_cycle; i++) { + /*int sf_offset =*/ pnalu->GetSE(); + } + } else if (POCtype != 2) { + return false; + } + // else for POCtype == 2, no additional data in stream + + /*int num_ref_frames =*/ pnalu->GetUE(); + /*int gaps_allowed =*/ pnalu->GetBit(); + + int mbs_width = (int)pnalu->GetUE(); + int mbs_height = (int)pnalu->GetUE(); + m_cx = (mbs_width+1) * 16; + m_cy = (mbs_height+1) * 16; + + // smoke test validation of sps + if ((m_cx > 2000) || (m_cy > 2000)) { + return false; + } + + // if this is false, then sizes are field sizes and need adjusting + m_bFrameOnly = pnalu->GetBit() ? true : false; + + if (!m_bFrameOnly) { + pnalu->Skip(1); // adaptive frame/field + } + pnalu->Skip(1); // direct 8x8 + +#if 0 + SetRect(&m_rcFrame, 0, 0, 0, 0); + bool bCrop = pnalu->GetBit() ? true : false; + if (bCrop) { + // get cropping rect + // store as exclusive, pixel parameters relative to frame + m_rcFrame.left = pnalu->GetUE() * 2; + m_rcFrame.right = pnalu->GetUE() * 2; + m_rcFrame.top = pnalu->GetUE() * 2; + m_rcFrame.bottom = pnalu->GetUE() * 2; + } + + if (!IsRectEmpty(&m_rcFrame)) { + m_rcFrame.right = m_cx - m_rcFrame.right; + m_rcFrame.bottom = m_cy - m_rcFrame.bottom; + } +#endif + // adjust rect from 2x2 units to pixels + + if (!m_bFrameOnly) { + // adjust heights from field to frame + m_cy *= 2; +#if 0 + m_rcFrame.top *= 2; + m_rcFrame.bottom *= 2; +#endif + } + + // .. rest are not interesting yet + m_nalu = *pnalu; + return true; +} + +// --- slice header -------------------- +bool +LFSliceHeader::Parse(LFNALUnit *pnalu){ + switch (pnalu->Type()) { + case LFNALUnit::NAL_IDR_Slice: + case LFNALUnit::NAL_Slice: + case LFNALUnit::NAL_PartitionA: + // all these begin with a slice header + break; + + default: + return false; + } + + // slice header has the 1-byte type, then one UE value, + // then the frame number. + pnalu->ResetBitstream(); + pnalu->Skip(8); // NALU type + pnalu->GetUE(); // first mb in slice + pnalu->GetUE(); // slice type + pnalu->GetUE(); // pic param set id + + m_framenum = (int)pnalu->GetWord(m_nBitsFrame); + return true; +} + +// --- SEI ---------------------- + + +LFSEIMessage::LFSEIMessage(LFNALUnit *pnalu){ + m_pnalu = pnalu; + const BYTE *p = pnalu->Start(); + p++; // nalu type byte + m_type = 0; + while (*p == 0xff) { + m_type += 255; + p++; + } + m_type += *p; + p++; + m_length = 0; + while (*p == 0xff) { + m_type += 255; + p++; + } + m_length += *p; + p++; + m_idxPayload = int(p - m_pnalu->Start()); +} + +LFavcCHeader::LFavcCHeader(const BYTE *header, int cBytes){ + if (cBytes < 8) { + return; + } + const BYTE *pEnd = header + cBytes; + + int cSeq = header[5] & 0x1f; + header += 6; + for (int i = 0; i < cSeq; i++) { + if ((header+2) > pEnd) { + return; + } + int cThis = (header[0] << 8) + header[1]; + header += 2; + if ((header+cThis) > pEnd) { + return; + } + if (i == 0) { + LFNALUnit n(header, cThis); + m_sps = n; + } + header += cThis; + } + if ((header + 3) >= pEnd) { + return; + } + int cPPS = header[0]; + if (cPPS > 0) { + int cThis = (header[1] << 8) + header[2]; + header += 3; + LFNALUnit n(header, cThis); + m_pps = n; + } +} + diff --git a/LFLiveKit/coder/H264/LFNALUnit.h b/LFLiveKit/coder/H264/LFNALUnit.h new file mode 100755 index 00000000..7b1a8461 --- /dev/null +++ b/LFLiveKit/coder/H264/LFNALUnit.h @@ -0,0 +1,242 @@ + +// +// NALUnit.h +// +// Basic parsing of H.264 NAL Units +// +// Geraint Davies, March 2004 +// +// Copyright (c) GDCL 2004-2008 http://www.gdcl.co.uk/license.htm + + + +#pragma once + +typedef unsigned char BYTE; +typedef unsigned long ULONG; +#ifndef NULL +#define NULL 0 +#endif + +class LFNALUnit +{ +public: + LFNALUnit(); + LFNALUnit(const BYTE* pStart, int len){ + m_pStart = m_pStartCodeStart = pStart; + m_cBytes = len; + ResetBitstream(); + } + virtual ~LFNALUnit() { + } + + // assignment copies a pointer into a fixed buffer managed elsewhere. We do not copy the data + LFNALUnit(const LFNALUnit &r){ + m_pStart = r.m_pStart; + m_cBytes = r.m_cBytes; + ResetBitstream(); + } + const LFNALUnit& operator = (const LFNALUnit &r) + { + m_pStart = r.m_pStart; + m_cBytes = r.m_cBytes; + ResetBitstream(); + return *this; + } + + enum eNALType { + NAL_Slice = 1, + NAL_PartitionA = 2, + NAL_PartitionB = 3, + NAL_PartitionC = 4, + NAL_IDR_Slice = 5, + NAL_SEI = 6, + NAL_Sequence_Params = 7, + NAL_Picture_Params = 8, + NAL_AUD = 9, + }; + + // identify a NAL unit within a buffer. + // If LengthSize is non-zero, it is the number of bytes + // of length field we expect. Otherwise, we expect start-code + // delimiters. + bool Parse(const BYTE *pBuffer, int cSpace, int LengthSize, bool bEnd); + + eNALType Type(){ + if (m_pStart == NULL) { + return eNALType(0); + } + return eNALType(m_pStart[0] & 0x1F); + } + + int Length(){ + return m_cBytes; + } + + const BYTE *Start(){ + return m_pStart; + } + + // bitwise access to data + void ResetBitstream(); + void Skip(int nBits); + + unsigned long GetWord(int nBits); + unsigned long GetUE(); + long GetSE(); + BYTE GetBYTE(); + unsigned long GetBit(); + + const BYTE *StartCodeStart() { + return m_pStartCodeStart; + } + +private: + bool GetStartCode(const BYTE *& pBegin, const BYTE *& pStart, int& cRemain); + +private: + const BYTE *m_pStartCodeStart; + const BYTE *m_pStart; + int m_cBytes; + + // bitstream access + int m_idx; + int m_nBits; + BYTE m_byte; + int m_cZeros; +}; + + + +// simple parser for the Sequence parameter set things that we need +class LFSeqParamSet +{ +public: + LFSeqParamSet(); + bool Parse(LFNALUnit *pnalu); + int FrameBits(){ + return m_FrameBits; + } + + long EncodedWidth(){ + return m_cx; + } + + long EncodedHeight(){ + return m_cy; + } + +#if 0 + long CroppedWidth(){ + if (IsRectEmpty(&m_rcFrame)) { + return EncodedWidth(); + } + return m_rcFrame.right - m_rcFrame.left; + } + + long CroppedHeight(){ + if (IsRectEmpty(&m_rcFrame)) { + return EncodedHeight(); + } + return m_rcFrame.bottom - m_rcFrame.top; + } + + RECT *CropRect(){ + return &m_rcFrame; + } + +#endif + bool Interlaced(){ + return !m_bFrameOnly; + } + + unsigned int Profile() { + return m_Profile; + } + + unsigned int Level() { + return m_Level; + } + + BYTE Compat() { + return m_Compatibility; + } + + LFNALUnit *NALU() { + return &m_nalu; + } + +private: + LFNALUnit m_nalu; + int m_FrameBits; + long m_cx; + long m_cy; +// RECT m_rcFrame; + bool m_bFrameOnly; + + int m_Profile; + int m_Level; + BYTE m_Compatibility; +}; + +// extract frame num from slice headers +class LFSliceHeader +{ +public: + LFSliceHeader(int nBitsFrame) + : m_framenum(0), + m_nBitsFrame(nBitsFrame){ + } + + bool Parse(LFNALUnit *pnalu); + int FrameNum(){ + return m_framenum; + } + +private: + int m_framenum; + int m_nBitsFrame; +}; + +// SEI message structure +class LFSEIMessage +{ +public: + LFSEIMessage(LFNALUnit* pnalu); + int Type() { + return m_type; + } + + int Length() { + return m_length; + } + + const BYTE *Payload() { + return m_pnalu->Start() + m_idxPayload; + } + +private: + LFNALUnit *m_pnalu; + int m_type; + int m_length; + int m_idxPayload; +}; + +// avcC structure from MP4 +class LFavcCHeader +{ +public: + LFavcCHeader(const BYTE* header, int cBytes); + LFNALUnit *sps() { + return &m_sps; + } + + LFNALUnit *pps() { + return &m_pps; + } + +private: + LFNALUnit m_sps; + LFNALUnit m_pps; +}; + diff --git a/LFLiveKit/coder/H264/LFVideoEncoder.h b/LFLiveKit/coder/H264/LFVideoEncoder.h new file mode 100755 index 00000000..83c47664 --- /dev/null +++ b/LFLiveKit/coder/H264/LFVideoEncoder.h @@ -0,0 +1,27 @@ +// +// VideoEncoder.h +// Encoder Demo +// +// Created by Geraint Davies on 14/01/2013. +// Copyright (c) 2013 GDCL http://www.gdcl.co.uk/license.htm +// + +#import +#import +#import +#import +#import + +@interface LFVideoEncoder : NSObject + + +@property NSString *path; +@property (nonatomic, readonly) NSUInteger bitrate; + ++ (LFVideoEncoder *)encoderForPath:(NSString *)path Height:(int)height andWidth:(int)width bitrate:(int)bitrate; + +- (void)initPath:(NSString *)path Height:(int)height andWidth:(int)width bitrate:(int)bitrate; +- (void)finishWithCompletionHandler:(void (^)(void))handler; +- (BOOL)encodeFrame:(CMSampleBufferRef)sampleBuffer; + +@end diff --git a/LFLiveKit/coder/H264/LFVideoEncoder.m b/LFLiveKit/coder/H264/LFVideoEncoder.m new file mode 100755 index 00000000..e60df9bb --- /dev/null +++ b/LFLiveKit/coder/H264/LFVideoEncoder.m @@ -0,0 +1,76 @@ +// +// LFVideoEncoder.m +// Encoder Demo +// +// Created by Geraint Davies on 14/01/2013. +// Copyright (c) 2013 GDCL http://www.gdcl.co.uk/license.htm +// + +#import "LFVideoEncoder.h" + +@implementation LFVideoEncoder +{ + AVAssetWriter *_writer; + AVAssetWriterInput *_writerInput; + NSString *_path; +} + +@synthesize path = _path; + ++ (LFVideoEncoder *)encoderForPath:(NSString *)path Height:(int)height andWidth:(int)width bitrate:(int)bitrate { + LFVideoEncoder *enc = [LFVideoEncoder alloc]; + [enc initPath:path Height:height andWidth:width bitrate:bitrate]; + return enc; +} + +- (void)initPath:(NSString *)path Height:(int)height andWidth:(int)width bitrate:(int)bitrate { + self.path = path; + _bitrate = bitrate; + + [[NSFileManager defaultManager] removeItemAtPath:self.path error:nil]; + NSURL *url = [NSURL fileURLWithPath:self.path]; + + NSDictionary *settings = @{ + AVVideoCodecKey: AVVideoCodecH264, + AVVideoWidthKey: @(width), + AVVideoHeightKey: @(height), + AVVideoCompressionPropertiesKey: @{ + AVVideoAverageBitRateKey: @(self.bitrate), + AVVideoMaxKeyFrameIntervalKey: @(30 * 2), + AVVideoProfileLevelKey: AVVideoProfileLevelH264Baseline41, + AVVideoAllowFrameReorderingKey: @NO, + } + }; + _writerInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:settings]; + _writerInput.expectsMediaDataInRealTime = YES; + + _writer = [AVAssetWriter assetWriterWithURL:url fileType:AVFileTypeQuickTimeMovie error:nil]; + [_writer addInput:_writerInput]; +} + +- (void)finishWithCompletionHandler:(void (^)(void))handler { + if (_writer.status == AVAssetWriterStatusWriting) { + [_writer finishWritingWithCompletionHandler:handler]; + } +} + +- (BOOL)encodeFrame:(CMSampleBufferRef)sampleBuffer { + if (CMSampleBufferDataIsReady(sampleBuffer)) { + if (_writer.status == AVAssetWriterStatusUnknown) { + CMTime startTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer); + [_writer startWriting]; + [_writer startSessionAtSourceTime:startTime]; + } + if (_writer.status == AVAssetWriterStatusFailed) { + //NSLog(@"AVAssetWriterStatusFailed"); + return NO; + } + if (_writerInput.readyForMoreMediaData == YES) { + [_writerInput appendSampleBuffer:sampleBuffer]; + return YES; + } + } + return NO; +} + +@end diff --git a/LFLiveKit/coder/LFAudioEncoding.h b/LFLiveKit/coder/LFAudioEncoding.h index 1f988866..d050f438 100755 --- a/LFLiveKit/coder/LFAudioEncoding.h +++ b/LFLiveKit/coder/LFAudioEncoding.h @@ -2,8 +2,8 @@ // LFAudioEncoding.h // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import @@ -11,21 +11,23 @@ #import "LFAudioFrame.h" #import "LFLiveAudioConfiguration.h" + + @protocol LFAudioEncoding; /// 编码器编码后回调 @protocol LFAudioEncodingDelegate @required -- (void)audioEncoder:(nullable id)encoder audioFrame:(nullable LFAudioFrame*)frame; +- (void)audioEncoder:(nullable id)encoder audioFrame:(nullable LFAudioFrame *)frame; @end /// 编码器抽象的接口 @protocol LFAudioEncoding @required -- (void)encodeAudioData:(AudioBufferList)inBufferList timeStamp:(uint64_t)timeStamp; +- (void)encodeAudioData:(nullable NSData*)audioData timeStamp:(uint64_t)timeStamp; - (void)stopEncoder; @optional -- (nullable instancetype)initWithAudioStreamConfiguration:(nullable LFLiveAudioConfiguration*)configuration; +- (nullable instancetype)initWithAudioStreamConfiguration:(nullable LFLiveAudioConfiguration *)configuration; - (void)setDelegate:(nullable id)delegate; -- (nullable NSData*)adtsData:(NSInteger)channel rawDataLength:(NSInteger)rawDataLength; +- (nullable NSData *)adtsData:(NSInteger)channel rawDataLength:(NSInteger)rawDataLength; @end diff --git a/LFLiveKit/coder/LFH264VideoEncoder.h b/LFLiveKit/coder/LFH264VideoEncoder.h new file mode 100644 index 00000000..f3cf1ac9 --- /dev/null +++ b/LFLiveKit/coder/LFH264VideoEncoder.h @@ -0,0 +1,17 @@ +// +// LFH264VideoEncoder +// LFLiveKit +// +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. +// + +#import "LFVideoEncoding.h" + +@interface LFH264VideoEncoder : NSObject { + +} + +- (void)shutdown; + +@end diff --git a/LFLiveKit/coder/LFH264VideoEncoder.mm b/LFLiveKit/coder/LFH264VideoEncoder.mm new file mode 100644 index 00000000..18e83dc6 --- /dev/null +++ b/LFLiveKit/coder/LFH264VideoEncoder.mm @@ -0,0 +1,263 @@ +// +// LFH264VideoEncoder +// LFLiveKit +// +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. +// + +#import +#import +#import "LFNALUnit.h" +#import "LFAVEncoder.h" +#import "LFH264VideoEncoder.h" +#import "LFVideoFrame.h" + +@interface LFH264VideoEncoder() { + FILE *fp; + NSInteger frameCount; + BOOL enabledWriteVideoFile; +} +@property (nonatomic, strong) LFLiveVideoConfiguration *configuration; +@property (nonatomic, weak) id h264Delegate; +@property (nonatomic) BOOL isBackGround; +@property (nonatomic) NSInteger currentVideoBitRate; +@property (nonatomic, strong) dispatch_queue_t sendQueue; + +@property (nonatomic, strong) LFAVEncoder *encoder; + +@property (nonatomic, strong) NSData *naluStartCode; +@property (nonatomic, strong) NSMutableData *videoSPSandPPS; +@property (nonatomic, strong) NSMutableData *spsData; +@property (nonatomic, strong) NSMutableData *ppsData; +@property (nonatomic, strong) NSMutableData *sei; +@property (nonatomic) CMTimeScale timescale; +@property (nonatomic, strong) NSMutableArray *orphanedFrames; +@property (nonatomic, strong) NSMutableArray *orphanedSEIFrames; +@property (nonatomic) CMTime lastPTS; +@end + +@implementation LFH264VideoEncoder + +#pragma mark -- LifeCycle +- (instancetype)initWithVideoStreamConfiguration:(LFLiveVideoConfiguration *)configuration { + if (self = [super init]) { + NSLog(@"USE LF264VideoEncoder"); + _configuration = configuration; + [self initCompressionSession]; + } + return self; +} + +- (void)initCompressionSession{ + _sendQueue = dispatch_queue_create("com.youku.laifeng.h264.sendframe", DISPATCH_QUEUE_SERIAL); + [self initializeNALUnitStartCode]; + _lastPTS = kCMTimeInvalid; + _timescale = 1000; + frameCount = 0; +#ifdef DEBUG + enabledWriteVideoFile = NO; + [self initForFilePath]; +#endif + + _encoder = [LFAVEncoder encoderForHeight:(int)_configuration.videoSize.height andWidth:(int)_configuration.videoSize.width bitrate:(int)_configuration.videoBitRate]; + [_encoder encodeWithBlock:^int(NSArray* dataArray, CMTimeValue ptsValue) { + [self incomingVideoFrames:dataArray ptsValue:ptsValue]; + return 0; + } onParams:^int(NSData *data) { + [self generateSPSandPPS]; + return 0; + }]; +} + +- (void) initializeNALUnitStartCode { + NSUInteger naluLength = 4; + uint8_t *nalu = (uint8_t*)malloc(naluLength * sizeof(uint8_t)); + nalu[0] = 0x00; + nalu[1] = 0x00; + nalu[2] = 0x00; + nalu[3] = 0x01; + _naluStartCode = [NSData dataWithBytesNoCopy:nalu length:naluLength freeWhenDone:YES]; +} + +- (void) generateSPSandPPS { + NSData* config = _encoder.getConfigData; + if (!config) { + return; + } + LFavcCHeader avcC((const BYTE*)[config bytes], (int)[config length]); + LFSeqParamSet seqParams; + seqParams.Parse(avcC.sps()); + + NSData* spsData = [NSData dataWithBytes:avcC.sps()->Start() length:avcC.sps()->Length()]; + NSData *ppsData = [NSData dataWithBytes:avcC.pps()->Start() length:avcC.pps()->Length()]; + + _spsData = [NSMutableData dataWithCapacity:avcC.sps()->Length()+_naluStartCode.length]; + _ppsData = [NSMutableData dataWithCapacity:avcC.pps()->Length()+_naluStartCode.length]; + + [_spsData appendData:_naluStartCode]; + [_spsData appendData:spsData]; + [_ppsData appendData:_naluStartCode]; + [_ppsData appendData:ppsData]; + + _videoSPSandPPS = [NSMutableData dataWithCapacity:avcC.sps()->Length() + avcC.pps()->Length() + _naluStartCode.length * 2]; + [_videoSPSandPPS appendData:_naluStartCode]; + [_videoSPSandPPS appendData:spsData]; + [_videoSPSandPPS appendData:_naluStartCode]; + [_videoSPSandPPS appendData:ppsData]; +} + + + +- (void)setVideoBitRate:(NSInteger)videoBitRate{ + _currentVideoBitRate = videoBitRate; + _encoder.bitrate = _currentVideoBitRate; +} + +- (NSInteger)videoBitRate{ + return _currentVideoBitRate; +} + +- (void)setDelegate:(id)delegate{ + _h264Delegate = delegate; +} + +- (void)encodeVideoData:(CVPixelBufferRef)pixelBuffer timeStamp:(uint64_t)timeStamp { + + CVPixelBufferLockBaseAddress(pixelBuffer, 0); + CMVideoFormatDescriptionRef videoInfo = NULL; + CMVideoFormatDescriptionCreateForImageBuffer(NULL, pixelBuffer, &videoInfo); + + CMTime frameTime = CMTimeMake(timeStamp, 1000); + CMTime duration = CMTimeMake(1, (int32_t)_configuration.videoFrameRate); + CMSampleTimingInfo timing = {duration, frameTime, kCMTimeInvalid}; + + CMSampleBufferRef sampleBuffer = NULL; + CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, YES, NULL, NULL, videoInfo, &timing, &sampleBuffer); + CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); + [_encoder encodeFrame:sampleBuffer]; + CFRelease(videoInfo); + CFRelease(sampleBuffer); + + frameCount++; +} + +- (void)addOrphanedFramesFromArray:(NSArray*)frames { + for (NSData *data in frames) { + unsigned char* pNal = (unsigned char*)[data bytes]; + int idc = pNal[0] & 0x60; + int naltype = pNal[0] & 0x1f; + if (idc == 0 && naltype == 6) { // SEI + [self.orphanedSEIFrames addObject:data]; + } else { + [self.orphanedFrames addObject:data]; + } + } +} + +- (void)writeVideoFrames:(NSArray*)frames pts:(CMTime)pts { + NSMutableArray *totalFrames = [NSMutableArray array]; + if (self.orphanedSEIFrames.count > 0) { + [totalFrames addObjectsFromArray:self.orphanedSEIFrames]; + [self.orphanedSEIFrames removeAllObjects]; + } + [totalFrames addObjectsFromArray:frames]; + + NSMutableData *aggregateFrameData = [NSMutableData data]; + //BOOL hasKeyframe = NO; + + for (NSData *data in totalFrames) { + unsigned char* pNal = (unsigned char*)[data bytes]; + int idc = pNal[0] & 0x60; + int naltype = pNal[0] & 0x1f; + NSData *videoData = nil; + + if (idc == 0 && naltype == 6) { // SEI + _sei = [NSMutableData dataWithData:data]; + continue; + } else if (naltype == 5) { // IDR + //hasKeyframe = YES; + NSMutableData *IDRData = [NSMutableData dataWithData:_videoSPSandPPS]; + if (_sei) { + [IDRData appendData:_naluStartCode]; + [IDRData appendData:_sei]; + _sei = nil; + } + [IDRData appendData:_naluStartCode]; + [IDRData appendData:data]; + videoData = IDRData; + } else { + NSMutableData *regularData = [NSMutableData dataWithData:_naluStartCode]; + [regularData appendData:data]; + videoData = regularData; + } + [aggregateFrameData appendData:videoData]; + + LFVideoFrame *videoFrame = [LFVideoFrame new]; + const char *dataBuffer = (const char *)aggregateFrameData.bytes; + videoFrame.data = [NSMutableData dataWithBytes:dataBuffer + _naluStartCode.length length:aggregateFrameData.length - _naluStartCode.length]; + videoFrame.timestamp = pts.value; + videoFrame.isKeyFrame = (naltype == 5); + videoFrame.sps = _spsData; + videoFrame.pps = _ppsData; + + if(self.h264Delegate && [self.h264Delegate respondsToSelector:@selector(videoEncoder:videoFrame:)]){ + [self.h264Delegate videoEncoder:self videoFrame:videoFrame]; + } + } + + if (self->enabledWriteVideoFile) { + fwrite(aggregateFrameData.bytes, 1, aggregateFrameData.length, self->fp); + } +} + +- (void) incomingVideoFrames:(NSArray*)frames ptsValue:(CMTimeValue)ptsValue { + if (ptsValue == 0) { + [self addOrphanedFramesFromArray:frames]; + return; + } + if (!_videoSPSandPPS) { + [self generateSPSandPPS]; + } + CMTime pts = CMTimeMake(ptsValue, _timescale); + if (self.orphanedFrames.count > 0) { + CMTime ptsDiff = CMTimeSubtract(pts, _lastPTS); + NSUInteger orphanedFramesCount = self.orphanedFrames.count; +// NSLog(@"lastPTS before first orphaned frame: %lld", _lastPTS.value); + for (NSData *frame in self.orphanedFrames) { + CMTime fakePTSDiff = CMTimeMultiplyByFloat64(ptsDiff, 1.0/(orphanedFramesCount + 1)); + CMTime fakePTS = CMTimeAdd(_lastPTS, fakePTSDiff); +// NSLog(@"orphan frame fakePTS: %lld", fakePTS.value); + [self writeVideoFrames:@[frame] pts:fakePTS]; + } +// NSLog(@"pts after orphaned frame: %lld", pts.value); + [self.orphanedFrames removeAllObjects]; + } + + [self writeVideoFrames:frames pts:pts]; + _lastPTS = pts; +} + + +- (void) dealloc { + [_encoder shutdown]; +} + +- (void)shutdown { + [_encoder encodeWithBlock:nil onParams:nil]; +} + +- (void)initForFilePath { + NSString *path = [self GetFilePathByfileName:@"IOSCamDemo.h264"]; + NSLog(@"%@", path); + self->fp = fopen([path cStringUsingEncoding:NSUTF8StringEncoding], "wb"); +} + +- (NSString *)GetFilePathByfileName:(NSString*)filename { + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSString *documentsDirectory = [paths objectAtIndex:0]; + NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:filename]; + return writablePath; +} + +@end diff --git a/LFLiveKit/coder/LFHardwareAudioEncoder.h b/LFLiveKit/coder/LFHardwareAudioEncoder.h index e40f83bc..cb028e45 100755 --- a/LFLiveKit/coder/LFHardwareAudioEncoder.h +++ b/LFLiveKit/coder/LFHardwareAudioEncoder.h @@ -2,8 +2,8 @@ // LFHardwareAudioEncoder.h // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFAudioEncoding.h" diff --git a/LFLiveKit/coder/LFHardwareAudioEncoder.m b/LFLiveKit/coder/LFHardwareAudioEncoder.m index d67efb69..64f97225 100755 --- a/LFLiveKit/coder/LFHardwareAudioEncoder.m +++ b/LFLiveKit/coder/LFHardwareAudioEncoder.m @@ -2,15 +2,19 @@ // LFHardwareAudioEncoder.m // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFHardwareAudioEncoder.h" @interface LFHardwareAudioEncoder (){ AudioConverterRef m_converter; + char *leftBuf; char *aacBuf; + NSInteger leftLength; + FILE *fp; + BOOL enabledWriteVideoFile; } @property (nonatomic, strong) LFLiveAudioConfiguration *configuration; @property (nonatomic, weak) id aacDeleage; @@ -19,61 +23,122 @@ @interface LFHardwareAudioEncoder (){ @implementation LFHardwareAudioEncoder -- (instancetype)initWithAudioStreamConfiguration:(LFLiveAudioConfiguration *)configuration{ - if(self = [super init]){ +- (instancetype)initWithAudioStreamConfiguration:(nullable LFLiveAudioConfiguration *)configuration { + if (self = [super init]) { + NSLog(@"USE LFHardwareAudioEncoder"); _configuration = configuration; + + if (!leftBuf) { + leftBuf = malloc(_configuration.bufferLength); + } + + if (!aacBuf) { + aacBuf = malloc(_configuration.bufferLength); + } + + +#ifdef DEBUG + enabledWriteVideoFile = NO; + [self initForFilePath]; +#endif } return self; } -- (void)dealloc{ - if(aacBuf) free(aacBuf); +- (void)dealloc { + if (aacBuf) free(aacBuf); + if (leftBuf) free(leftBuf); } #pragma mark -- LFAudioEncoder -- (void)setDelegate:(id)delegate{ +- (void)setDelegate:(id)delegate { _aacDeleage = delegate; } -- (void)encodeAudioData:(AudioBufferList)inBufferList timeStamp:(uint64_t)timeStamp{ - if (![self createAudioConvert]){ +- (void)encodeAudioData:(nullable NSData*)audioData timeStamp:(uint64_t)timeStamp { + if (![self createAudioConvert]) { return; } - if(!aacBuf){ - aacBuf = malloc(inBufferList.mBuffers[0].mDataByteSize); + if(leftLength + audioData.length >= self.configuration.bufferLength){ + ///<  发送 + NSInteger totalSize = leftLength + audioData.length; + NSInteger encodeCount = totalSize/self.configuration.bufferLength; + char *totalBuf = malloc(totalSize); + char *p = totalBuf; + + memset(totalBuf, (int)totalSize, 0); + memcpy(totalBuf, leftBuf, leftLength); + memcpy(totalBuf + leftLength, audioData.bytes, audioData.length); + + for(NSInteger index = 0;index < encodeCount;index++){ + [self encodeBuffer:p timeStamp:timeStamp]; + p += self.configuration.bufferLength; + } + + leftLength = totalSize%self.configuration.bufferLength; + memset(leftBuf, 0, self.configuration.bufferLength); + memcpy(leftBuf, totalBuf + (totalSize -leftLength), leftLength); + + free(totalBuf); + + }else{ + ///< 积累 + memcpy(leftBuf+leftLength, audioData.bytes, audioData.length); + leftLength = leftLength + audioData.length; } +} + +- (void)encodeBuffer:(char*)buf timeStamp:(uint64_t)timeStamp{ + + AudioBuffer inBuffer; + inBuffer.mNumberChannels = 1; + inBuffer.mData = buf; + inBuffer.mDataByteSize = (UInt32)self.configuration.bufferLength; + + AudioBufferList buffers; + buffers.mNumberBuffers = 1; + buffers.mBuffers[0] = inBuffer; + // 初始化一个输出缓冲列表 AudioBufferList outBufferList; - outBufferList.mNumberBuffers = 1; - outBufferList.mBuffers[0].mNumberChannels = inBufferList.mBuffers[0].mNumberChannels; - outBufferList.mBuffers[0].mDataByteSize = inBufferList.mBuffers[0].mDataByteSize; // 设置缓冲区大小 - outBufferList.mBuffers[0].mData = aacBuf; // 设置AAC缓冲区 - UInt32 outputDataPacketSize = 1; - if (AudioConverterFillComplexBuffer(m_converter, inputDataProc, &inBufferList, &outputDataPacketSize, &outBufferList, NULL) != noErr){ + outBufferList.mNumberBuffers = 1; + outBufferList.mBuffers[0].mNumberChannels = inBuffer.mNumberChannels; + outBufferList.mBuffers[0].mDataByteSize = inBuffer.mDataByteSize; // 设置缓冲区大小 + outBufferList.mBuffers[0].mData = aacBuf; // 设置AAC缓冲区 + UInt32 outputDataPacketSize = 1; + if (AudioConverterFillComplexBuffer(m_converter, inputDataProc, &buffers, &outputDataPacketSize, &outBufferList, NULL) != noErr) { return; } + LFAudioFrame *audioFrame = [LFAudioFrame new]; audioFrame.timestamp = timeStamp; audioFrame.data = [NSData dataWithBytes:aacBuf length:outBufferList.mBuffers[0].mDataByteSize]; - + char exeData[2]; exeData[0] = _configuration.asc[0]; exeData[1] = _configuration.asc[1]; - audioFrame.audioInfo =[NSData dataWithBytes:exeData length:2]; - if(self.aacDeleage && [self.aacDeleage respondsToSelector:@selector(audioEncoder:audioFrame:)]){ + audioFrame.audioInfo = [NSData dataWithBytes:exeData length:2]; + if (self.aacDeleage && [self.aacDeleage respondsToSelector:@selector(audioEncoder:audioFrame:)]) { [self.aacDeleage audioEncoder:self audioFrame:audioFrame]; } + + if (self->enabledWriteVideoFile) { + NSData *adts = [self adtsData:_configuration.numberOfChannels rawDataLength:audioFrame.data.length]; + fwrite(adts.bytes, 1, adts.length, self->fp); + fwrite(audioFrame.data.bytes, 1, audioFrame.data.length, self->fp); + } + } -- (void)stopEncoder{ +- (void)stopEncoder { } #pragma mark -- CustomMethod --(BOOL)createAudioConvert{ //根据输入样本初始化一个编码转换器 - if (m_converter != nil){ +- (BOOL)createAudioConvert { //根据输入样本初始化一个编码转换器 + if (m_converter != nil) { return TRUE; } @@ -89,10 +154,10 @@ -(BOOL)createAudioConvert{ //根据输入样本初始化一个编码转换器 AudioStreamBasicDescription outputFormat; // 这里开始是输出音频格式 memset(&outputFormat, 0, sizeof(outputFormat)); - outputFormat.mSampleRate = inputFormat.mSampleRate; // 采样率保持一致 - outputFormat.mFormatID = kAudioFormatMPEG4AAC; // AAC编码 kAudioFormatMPEG4AAC kAudioFormatMPEG4AAC_HE_V2 + outputFormat.mSampleRate = inputFormat.mSampleRate; // 采样率保持一致 + outputFormat.mFormatID = kAudioFormatMPEG4AAC; // AAC编码 kAudioFormatMPEG4AAC kAudioFormatMPEG4AAC_HE_V2 outputFormat.mChannelsPerFrame = (UInt32)_configuration.numberOfChannels;; - outputFormat.mFramesPerPacket = 1024; // AAC一帧是1024个字节 + outputFormat.mFramesPerPacket = 1024; // AAC一帧是1024个字节 const OSType subtype = kAudioFormatMPEG4AAC; AudioClassDescription requestedCodecs[2] = { @@ -107,47 +172,31 @@ -(BOOL)createAudioConvert{ //根据输入样本初始化一个编码转换器 kAppleHardwareAudioCodecManufacturer } }; - OSStatus result = AudioConverterNewSpecific(&inputFormat, &outputFormat, 2, requestedCodecs, &m_converter); - - if(result != noErr) return NO; + OSStatus result = AudioConverterNewSpecific(&inputFormat, &outputFormat, 2, requestedCodecs, &m_converter);; + UInt32 outputBitrate = _configuration.audioBitrate; + UInt32 propSize = sizeof(outputBitrate); - return YES; -} - --(AudioClassDescription*)getAudioClassDescriptionWithType:(UInt32)type fromManufacturer:(UInt32)manufacturer { // 获得相应的编码器 - static AudioClassDescription audioDesc; - UInt32 encoderSpecifier = type, size = 0; - OSStatus status; - - memset(&audioDesc, 0, sizeof(audioDesc)); - status = AudioFormatGetPropertyInfo(kAudioFormatProperty_Encoders, sizeof(encoderSpecifier), &encoderSpecifier, &size); - if (status) { - return nil; + if(result == noErr) { + result = AudioConverterSetProperty(m_converter, kAudioConverterEncodeBitRate, propSize, &outputBitrate); } - uint32_t count = size / sizeof(AudioClassDescription); - AudioClassDescription descs[count]; - AudioFormatGetProperty(kAudioFormatProperty_Encoders, sizeof(encoderSpecifier), &encoderSpecifier, &size, descs); - for (uint32_t i = 0; i < count; i++){ - if ((type == descs[i].mSubType) && (manufacturer == descs[i].mManufacturer)){ - memcpy(&audioDesc, &descs[i], sizeof(audioDesc)); - break; - } - } - return &audioDesc; + return YES; } + #pragma mark -- AudioCallBack -OSStatus inputDataProc(AudioConverterRef inConverter, UInt32 *ioNumberDataPackets, AudioBufferList *ioData,AudioStreamPacketDescription **outDataPacketDescription, void *inUserData) { //AudioConverterFillComplexBuffer 编码过程中,会要求这个函数来填充输入数据,也就是原始PCM数据 - AudioBufferList bufferList = *(AudioBufferList*)inUserData; +OSStatus inputDataProc(AudioConverterRef inConverter, UInt32 *ioNumberDataPackets, AudioBufferList *ioData, AudioStreamPacketDescription * *outDataPacketDescription, void *inUserData) { //AudioConverterFillComplexBuffer 编码过程中,会要求这个函数来填充输入数据,也就是原始PCM数据 + AudioBufferList bufferList = *(AudioBufferList *)inUserData; ioData->mBuffers[0].mNumberChannels = 1; - ioData->mBuffers[0].mData = bufferList.mBuffers[0].mData; - ioData->mBuffers[0].mDataByteSize = bufferList.mBuffers[0].mDataByteSize; + ioData->mBuffers[0].mData = bufferList.mBuffers[0].mData; + ioData->mBuffers[0].mDataByteSize = bufferList.mBuffers[0].mDataByteSize; return noErr; } + +#pragma mark -- Custom Method /** * Add ADTS header at the beginning of each and every AAC packet. * This is needed as MediaCodec encoder generates a packet of raw @@ -157,18 +206,18 @@ -(AudioClassDescription*)getAudioClassDescriptionWithType:(UInt32)type fromManuf * See: http://wiki.multimedia.cx/index.php?title=ADTS * Also: http://wiki.multimedia.cx/index.php?title=MPEG-4_Audio#Channel_Configurations **/ -- (NSData*)adtsData:(NSInteger)channel rawDataLength:(NSInteger)rawDataLength { +- (NSData *)adtsData:(NSInteger)channel rawDataLength:(NSInteger)rawDataLength { int adtsLength = 7; char *packet = malloc(sizeof(char) * adtsLength); // Variables Recycled by addADTStoPacket int profile = 2; //AAC LC //39=MediaCodecInfo.CodecProfileLevel.AACObjectELD; - int freqIdx = 4; //44.1KHz + NSInteger freqIdx = [self sampleRateIndex:self.configuration.audioSampleRate]; //44.1KHz int chanCfg = (int)channel; //MPEG-4 Audio Channel Configuration. 1 Channel front-center NSUInteger fullLength = adtsLength + rawDataLength; // fill in ADTS data - packet[0] = (char)0xFF; // 11111111 = syncword - packet[1] = (char)0xF9; // 1111 1 00 1 = syncword MPEG-2 Layer CRC + packet[0] = (char)0xFF; // 11111111 = syncword + packet[1] = (char)0xF9; // 1111 1 00 1 = syncword MPEG-2 Layer CRC packet[2] = (char)(((profile-1)<<6) + (freqIdx<<2) +(chanCfg>>2)); packet[3] = (char)(((chanCfg&3)<<6) + (fullLength>>11)); packet[4] = (char)((fullLength&0x7FF) >> 3); @@ -178,4 +227,65 @@ - (NSData*)adtsData:(NSInteger)channel rawDataLength:(NSInteger)rawDataLength { return data; } +- (NSInteger)sampleRateIndex:(NSInteger)frequencyInHz { + NSInteger sampleRateIndex = 0; + switch (frequencyInHz) { + case 96000: + sampleRateIndex = 0; + break; + case 88200: + sampleRateIndex = 1; + break; + case 64000: + sampleRateIndex = 2; + break; + case 48000: + sampleRateIndex = 3; + break; + case 44100: + sampleRateIndex = 4; + break; + case 32000: + sampleRateIndex = 5; + break; + case 24000: + sampleRateIndex = 6; + break; + case 22050: + sampleRateIndex = 7; + break; + case 16000: + sampleRateIndex = 8; + break; + case 12000: + sampleRateIndex = 9; + break; + case 11025: + sampleRateIndex = 10; + break; + case 8000: + sampleRateIndex = 11; + break; + case 7350: + sampleRateIndex = 12; + break; + default: + sampleRateIndex = 15; + } + return sampleRateIndex; +} + +- (void)initForFilePath { + NSString *path = [self GetFilePathByfileName:@"IOSCamDemo_HW.aac"]; + NSLog(@"%@", path); + self->fp = fopen([path cStringUsingEncoding:NSUTF8StringEncoding], "wb"); +} + +- (NSString *)GetFilePathByfileName:(NSString*)filename { + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSString *documentsDirectory = [paths objectAtIndex:0]; + NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:filename]; + return writablePath; +} + @end diff --git a/LFLiveKit/coder/LFHardwareVideoEncoder.h b/LFLiveKit/coder/LFHardwareVideoEncoder.h index 083d88ca..41c6e002 100755 --- a/LFLiveKit/coder/LFHardwareVideoEncoder.h +++ b/LFLiveKit/coder/LFHardwareVideoEncoder.h @@ -2,8 +2,8 @@ // LFHardwareVideoEncoder.h // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFVideoEncoding.h" diff --git a/LFLiveKit/coder/LFHardwareVideoEncoder.m b/LFLiveKit/coder/LFHardwareVideoEncoder.m index f3cdeb02..6c3d20fe 100755 --- a/LFLiveKit/coder/LFHardwareVideoEncoder.m +++ b/LFLiveKit/coder/LFHardwareVideoEncoder.m @@ -2,10 +2,9 @@ // LFHardwareVideoEncoder.m // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // - #import "LFHardwareVideoEncoder.h" #import @@ -19,77 +18,76 @@ @interface LFHardwareVideoEncoder (){ } @property (nonatomic, strong) LFLiveVideoConfiguration *configuration; -@property (nonatomic,weak) id h264Delegate; -@property (nonatomic) BOOL isBackGround; +@property (nonatomic, weak) id h264Delegate; @property (nonatomic) NSInteger currentVideoBitRate; +@property (nonatomic) BOOL isBackGround; @end @implementation LFHardwareVideoEncoder #pragma mark -- LifeCycle -- (instancetype)initWithVideoStreamConfiguration:(LFLiveVideoConfiguration *)configuration{ - if(self = [super init]){ +- (instancetype)initWithVideoStreamConfiguration:(LFLiveVideoConfiguration *)configuration { + if (self = [super init]) { + NSLog(@"USE LFHardwareVideoEncoder"); _configuration = configuration; - [self initCompressionSession]; - + [self resetCompressionSession]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterBackground:) name:UIApplicationWillResignActiveNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground:) name:UIApplicationDidBecomeActiveNotification object:nil]; #ifdef DEBUG enabledWriteVideoFile = NO; [self initForFilePath]; #endif - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterBackground:) name:UIApplicationWillResignActiveNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground:) name:UIApplicationDidBecomeActiveNotification object:nil]; } return self; } -- (void)initCompressionSession{ - if(compressionSession){ +- (void)resetCompressionSession { + if (compressionSession) { VTCompressionSessionCompleteFrames(compressionSession, kCMTimeInvalid); - + VTCompressionSessionInvalidate(compressionSession); CFRelease(compressionSession); compressionSession = NULL; } - + OSStatus status = VTCompressionSessionCreate(NULL, _configuration.videoSize.width, _configuration.videoSize.height, kCMVideoCodecType_H264, NULL, NULL, NULL, VideoCompressonOutputCallback, (__bridge void *)self, &compressionSession); - if(status != noErr){ + if (status != noErr) { return; } - + _currentVideoBitRate = _configuration.videoBitRate; - VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_MaxKeyFrameInterval,(__bridge CFTypeRef)@(_configuration.videoMaxKeyframeInterval)); - VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration,(__bridge CFTypeRef)@(_configuration.videoMaxKeyframeInterval)); + VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_MaxKeyFrameInterval, (__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)]; + NSArray *limit = @[@(_configuration.videoBitRate * 1.5/8), @(1)]; VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_DataRateLimits, (__bridge CFArrayRef)limit); - VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_RealTime, kCFBooleanFalse); + VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_RealTime, kCFBooleanTrue); VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_ProfileLevel, kVTProfileLevel_H264_Main_AutoLevel); - VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_AllowFrameReordering, kCFBooleanFalse); + VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_AllowFrameReordering, kCFBooleanTrue); VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_H264EntropyMode, kVTH264EntropyMode_CABAC); VTCompressionSessionPrepareToEncodeFrames(compressionSession); - + } -- (void)setVideoBitRate:(NSInteger)videoBitRate{ +- (void)setVideoBitRate:(NSInteger)videoBitRate { if(_isBackGround) return; VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_AverageBitRate, (__bridge CFTypeRef)@(videoBitRate)); - NSArray *limit = @[@(videoBitRate * 1.5/8),@(1)]; + NSArray *limit = @[@(videoBitRate * 1.5/8), @(1)]; VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_DataRateLimits, (__bridge CFArrayRef)limit); _currentVideoBitRate = videoBitRate; } --(NSInteger)videoBitRate{ +- (NSInteger)videoBitRate { return _currentVideoBitRate; } -- (void)dealloc{ - if(compressionSession != NULL) - { +- (void)dealloc { + if (compressionSession != NULL) { VTCompressionSessionCompleteFrames(compressionSession, kCMTimeInvalid); - + VTCompressionSessionInvalidate(compressionSession); CFRelease(compressionSession); compressionSession = NULL; @@ -98,90 +96,88 @@ - (void)dealloc{ } #pragma mark -- LFVideoEncoder -- (void)encodeVideoData:(CVImageBufferRef)pixelBuffer timeStamp:(uint64_t)timeStamp{ +- (void)encodeVideoData:(CVPixelBufferRef)pixelBuffer timeStamp:(uint64_t)timeStamp { if(_isBackGround) return; - - frameCount ++; - CMTime presentationTimeStamp = CMTimeMake(frameCount, 1000); + frameCount++; + CMTime presentationTimeStamp = CMTimeMake(frameCount, (int32_t)_configuration.videoFrameRate); VTEncodeInfoFlags flags; CMTime duration = CMTimeMake(1, (int32_t)_configuration.videoFrameRate); - + NSDictionary *properties = nil; - if(frameCount % (int32_t)_configuration.videoMaxKeyframeInterval == 0){ + if (frameCount % (int32_t)_configuration.videoMaxKeyframeInterval == 0) { properties = @{(__bridge NSString *)kVTEncodeFrameOptionKey_ForceKeyFrame: @YES}; } NSNumber *timeNumber = @(timeStamp); - - VTCompressionSessionEncodeFrame(compressionSession, pixelBuffer, presentationTimeStamp, duration, (__bridge CFDictionaryRef)properties, (__bridge_retained void *)timeNumber, &flags); + + OSStatus status = VTCompressionSessionEncodeFrame(compressionSession, pixelBuffer, presentationTimeStamp, duration, (__bridge CFDictionaryRef)properties, (__bridge_retained void *)timeNumber, &flags); + if(status != noErr){ + [self resetCompressionSession]; + } } -- (void)stopEncoder{ +- (void)stopEncoder { VTCompressionSessionCompleteFrames(compressionSession, kCMTimeIndefinite); } -- (void)setDelegate:(id)delegate{ +- (void)setDelegate:(id)delegate { _h264Delegate = delegate; } -#pragma mark -- NSNotification +#pragma mark -- Notification - (void)willEnterBackground:(NSNotification*)notification{ _isBackGround = YES; } - (void)willEnterForeground:(NSNotification*)notification{ - [self initCompressionSession]; + [self resetCompressionSession]; _isBackGround = NO; } #pragma mark -- VideoCallBack -static void VideoCompressonOutputCallback(void *VTref, void *VTFrameRef, OSStatus status, VTEncodeInfoFlags infoFlags, CMSampleBufferRef sampleBuffer) -{ - if(!sampleBuffer) return; +static void VideoCompressonOutputCallback(void *VTref, void *VTFrameRef, OSStatus status, VTEncodeInfoFlags infoFlags, CMSampleBufferRef sampleBuffer){ + if (!sampleBuffer) return; CFArrayRef array = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, true); - if(!array) return; + if (!array) return; CFDictionaryRef dic = (CFDictionaryRef)CFArrayGetValueAtIndex(array, 0); - if(!dic) return; - + if (!dic) return; + BOOL keyframe = !CFDictionaryContainsKey(dic, kCMSampleAttachmentKey_NotSync); - uint64_t timeStamp = [((__bridge_transfer NSNumber*)VTFrameRef) longLongValue]; - + uint64_t timeStamp = [((__bridge_transfer NSNumber *)VTFrameRef) longLongValue]; + LFHardwareVideoEncoder *videoEncoder = (__bridge LFHardwareVideoEncoder *)VTref; - if(status != noErr){ + if (status != noErr) { return; } - - if (keyframe && !videoEncoder->sps) - { + + if (keyframe && !videoEncoder->sps) { CMFormatDescriptionRef format = CMSampleBufferGetFormatDescription(sampleBuffer); - + size_t sparameterSetSize, sparameterSetCount; const uint8_t *sparameterSet; - OSStatus statusCode = CMVideoFormatDescriptionGetH264ParameterSetAtIndex(format, 0, &sparameterSet, &sparameterSetSize, &sparameterSetCount, 0 ); - if (statusCode == noErr) - { + OSStatus statusCode = CMVideoFormatDescriptionGetH264ParameterSetAtIndex(format, 0, &sparameterSet, &sparameterSetSize, &sparameterSetCount, 0); + if (statusCode == noErr) { size_t pparameterSetSize, pparameterSetCount; const uint8_t *pparameterSet; - OSStatus statusCode = CMVideoFormatDescriptionGetH264ParameterSetAtIndex(format, 1, &pparameterSet, &pparameterSetSize, &pparameterSetCount, 0 ); - if (statusCode == noErr) - { + OSStatus statusCode = CMVideoFormatDescriptionGetH264ParameterSetAtIndex(format, 1, &pparameterSet, &pparameterSetSize, &pparameterSetCount, 0); + if (statusCode == noErr) { videoEncoder->sps = [NSData dataWithBytes:sparameterSet length:sparameterSetSize]; videoEncoder->pps = [NSData dataWithBytes:pparameterSet length:pparameterSetSize]; - - if(videoEncoder->enabledWriteVideoFile){ + + if (videoEncoder->enabledWriteVideoFile) { NSMutableData *data = [[NSMutableData alloc] init]; - uint8_t header[] = {0x00,0x00,0x00,0x01}; + uint8_t header[] = {0x00, 0x00, 0x00, 0x01}; [data appendBytes:header length:4]; [data appendData:videoEncoder->sps]; [data appendBytes:header length:4]; [data appendData:videoEncoder->pps]; - fwrite(data.bytes, 1,data.length,videoEncoder->fp); + fwrite(data.bytes, 1, data.length, videoEncoder->fp); } - + } } } - - + + CMBlockBufferRef dataBuffer = CMSampleBufferGetDataBuffer(sampleBuffer); size_t length, totalLength; char *dataPointer; @@ -193,7 +189,7 @@ static void VideoCompressonOutputCallback(void *VTref, void *VTFrameRef, OSStatu // Read the NAL unit length uint32_t NALUnitLength = 0; memcpy(&NALUnitLength, dataPointer + bufferOffset, AVCCHeaderLength); - + NALUnitLength = CFSwapInt32BigToHost(NALUnitLength); LFVideoFrame *videoFrame = [LFVideoFrame new]; @@ -202,56 +198,44 @@ static void VideoCompressonOutputCallback(void *VTref, void *VTFrameRef, OSStatu videoFrame.isKeyFrame = keyframe; videoFrame.sps = videoEncoder->sps; videoFrame.pps = videoEncoder->pps; - - if(videoEncoder.h264Delegate && [videoEncoder.h264Delegate respondsToSelector:@selector(videoEncoder:videoFrame:)]){ + + if (videoEncoder.h264Delegate && [videoEncoder.h264Delegate respondsToSelector:@selector(videoEncoder:videoFrame:)]) { [videoEncoder.h264Delegate videoEncoder:videoEncoder videoFrame:videoFrame]; } - - if(videoEncoder->enabledWriteVideoFile){ + + if (videoEncoder->enabledWriteVideoFile) { NSMutableData *data = [[NSMutableData alloc] init]; - if(keyframe){ - uint8_t header[] = {0x00,0x00,0x00,0x01}; + if (keyframe) { + uint8_t header[] = {0x00, 0x00, 0x00, 0x01}; [data appendBytes:header length:4]; - }else{ - uint8_t header[] = {0x00,0x00,0x01}; + } else { + uint8_t header[] = {0x00, 0x00, 0x01}; [data appendBytes:header length:3]; } [data appendData:videoFrame.data]; - - fwrite(data.bytes, 1,data.length,videoEncoder->fp); + + fwrite(data.bytes, 1, data.length, videoEncoder->fp); } - + bufferOffset += AVCCHeaderLength + NALUnitLength; - + } - + } } -- (void)initForFilePath -{ - char *path = [self GetFilePathByfileName:"IOSCamDemo.h264"]; - NSLog(@"%s",path); - self->fp = fopen(path,"wb"); +- (void)initForFilePath { + NSString *path = [self GetFilePathByfileName:@"IOSCamDemo.h264"]; + NSLog(@"%@", path); + self->fp = fopen([path cStringUsingEncoding:NSUTF8StringEncoding], "wb"); } - -- (char*)GetFilePathByfileName:(char*)filename -{ - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES); +- (NSString *)GetFilePathByfileName:(NSString*)filename { + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; - NSString *strName = [NSString stringWithFormat:@"%s",filename]; - - NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:strName]; - - NSUInteger len = [writablePath length]; - - char *filepath = (char*)malloc(sizeof(char) * (len + 1)); - - [writablePath getCString:filepath maxLength:len + 1 encoding:[NSString defaultCStringEncoding]]; - - return filepath; + NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:filename]; + return writablePath; } @end diff --git a/LFLiveKit/coder/LFVideoEncoding.h b/LFLiveKit/coder/LFVideoEncoding.h index 73ece788..252b2a14 100755 --- a/LFLiveKit/coder/LFVideoEncoding.h +++ b/LFLiveKit/coder/LFVideoEncoding.h @@ -2,8 +2,8 @@ // LFVideoEncoding.h // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import @@ -14,18 +14,17 @@ /// 编码器编码后回调 @protocol LFVideoEncodingDelegate @required -- (void)videoEncoder:(nullable id)encoder videoFrame:(nullable LFVideoFrame*)frame; +- (void)videoEncoder:(nullable id)encoder videoFrame:(nullable LFVideoFrame *)frame; @end /// 编码器抽象的接口 @protocol LFVideoEncoding @required -- (void)encodeVideoData:(nullable CVImageBufferRef)pixelBuffer timeStamp:(uint64_t)timeStamp; -- (void)stopEncoder; +- (void)encodeVideoData:(nullable CVPixelBufferRef)pixelBuffer timeStamp:(uint64_t)timeStamp; @optional @property (nonatomic, assign) NSInteger videoBitRate; -- (nullable instancetype)initWithVideoStreamConfiguration:(nullable LFLiveVideoConfiguration*)configuration; +- (nullable instancetype)initWithVideoStreamConfiguration:(nullable LFLiveVideoConfiguration *)configuration; - (void)setDelegate:(nullable id)delegate; - +- (void)stopEncoder; @end diff --git a/LFLiveKit/configuration/LFLiveAudioConfiguration.h b/LFLiveKit/configuration/LFLiveAudioConfiguration.h index 32e8c38a..812dd55c 100755 --- a/LFLiveKit/configuration/LFLiveAudioConfiguration.h +++ b/LFLiveKit/configuration/LFLiveAudioConfiguration.h @@ -2,14 +2,14 @@ // LFLiveAudioConfiguration.h // LFLiveKit // -// Created by 倾慕 on 16/5/1. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import -/// 音频码率 -typedef NS_ENUM(NSUInteger, LFLiveAudioBitRate) { +/// 音频码率 (默认96Kbps) +typedef NS_ENUM (NSUInteger, LFLiveAudioBitRate) { /// 32Kbps 音频码率 LFLiveAudioBitRate_32Kbps = 32000, /// 64Kbps 音频码率 @@ -18,35 +18,37 @@ typedef NS_ENUM(NSUInteger, LFLiveAudioBitRate) { LFLiveAudioBitRate_96Kbps = 96000, /// 128Kbps 音频码率 LFLiveAudioBitRate_128Kbps = 128000, - /// 默认音频码率,默认为 64Kbps - LFLiveAudioBitRate_Default = LFLiveAudioBitRate_64Kbps + /// 默认音频码率,默认为 96Kbps + LFLiveAudioBitRate_Default = LFLiveAudioBitRate_96Kbps }; -/// 采样率 (默认44.1Hz iphoneg6以上48Hz) -typedef NS_ENUM(NSUInteger, LFLiveAudioSampleRate){ - /// 44.1Hz 采样率 +/// 音频采样率 (默认44.1KHz) +typedef NS_ENUM (NSUInteger, LFLiveAudioSampleRate){ + /// 16KHz 采样率 + LFLiveAudioSampleRate_16000Hz = 16000, + /// 44.1KHz 采样率 LFLiveAudioSampleRate_44100Hz = 44100, - /// 48Hz 采样率 + /// 48KHz 采样率 LFLiveAudioSampleRate_48000Hz = 48000, - /// 默认音频码率,默认为 64Kbps + /// 默认音频采样率,默认为 44.1KHz LFLiveAudioSampleRate_Default = LFLiveAudioSampleRate_44100Hz }; /// Audio Live quality(音频质量) -typedef NS_ENUM(NSUInteger, LFLiveAudioQuality){ - /// 高音频质量 audio sample rate: 44MHz(默认44.1Hz iphoneg6以上48Hz), audio bitrate: 32Kbps +typedef NS_ENUM (NSUInteger, LFLiveAudioQuality){ + /// 低音频质量 audio sample rate: 16KHz audio bitrate: numberOfChannels 1 : 32Kbps 2 : 64Kbps LFLiveAudioQuality_Low = 0, - /// 高音频质量 audio sample rate: 44MHz(默认44.1Hz iphoneg6以上48Hz), audio bitrate: 64Kbps + /// 中音频质量 audio sample rate: 44.1KHz audio bitrate: 96Kbps LFLiveAudioQuality_Medium = 1, - /// 高音频质量 audio sample rate: 44MHz(默认44.1Hz iphoneg6以上48Hz), audio bitrate: 96Kbps + /// 高音频质量 audio sample rate: 44.1MHz audio bitrate: 128Kbps LFLiveAudioQuality_High = 2, - /// 高音频质量 audio sample rate: 44MHz(默认44.1Hz iphoneg6以上48Hz), audio bitrate: 128Kbps + /// 超高音频质量 audio sample rate: 48KHz, audio bitrate: 128Kbps LFLiveAudioQuality_VeryHigh = 3, - /// 默认音频质量 audio sample rate: 44MHz(默认44.1Hz iphoneg6以上48Hz), audio bitrate: 64Kbps - LFLiveAudioQuality_Default = LFLiveAudioQuality_Medium + /// 默认音频质量 audio sample rate: 44.1KHz, audio bitrate: 96Kbps + LFLiveAudioQuality_Default = LFLiveAudioQuality_High }; -@interface LFLiveAudioConfiguration : NSObject +@interface LFLiveAudioConfiguration : NSObject /// 默认音频配置 + (instancetype)defaultConfiguration; @@ -61,9 +63,11 @@ typedef NS_ENUM(NSUInteger, LFLiveAudioQuality){ @property (nonatomic, assign) NSUInteger numberOfChannels; /// 采样率 @property (nonatomic, assign) LFLiveAudioSampleRate audioSampleRate; -// 码率 +/// 码率 @property (nonatomic, assign) LFLiveAudioBitRate audioBitrate; /// flv编码音频头 44100 为0x12 0x10 -@property (nonatomic ,assign,readonly) char *asc; +@property (nonatomic, assign, readonly) char *asc; +/// 缓存区长度 +@property (nonatomic, assign,readonly) NSUInteger bufferLength; @end diff --git a/LFLiveKit/configuration/LFLiveAudioConfiguration.m b/LFLiveKit/configuration/LFLiveAudioConfiguration.m index d520c6b5..5ecdea72 100755 --- a/LFLiveKit/configuration/LFLiveAudioConfiguration.m +++ b/LFLiveKit/configuration/LFLiveAudioConfiguration.m @@ -2,8 +2,8 @@ // LFLiveAudioConfiguration.m // LFLiveKit // -// Created by 倾慕 on 16/5/1. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFLiveAudioConfiguration.h" @@ -12,165 +12,124 @@ @implementation LFLiveAudioConfiguration #pragma mark -- LifyCycle -+ (instancetype)defaultConfiguration{ ++ (instancetype)defaultConfiguration { LFLiveAudioConfiguration *audioConfig = [LFLiveAudioConfiguration defaultConfigurationForQuality:LFLiveAudioQuality_Default]; return audioConfig; } -+ (instancetype)defaultConfigurationForQuality:(LFLiveAudioQuality)audioQuality{ ++ (instancetype)defaultConfigurationForQuality:(LFLiveAudioQuality)audioQuality { LFLiveAudioConfiguration *audioConfig = [LFLiveAudioConfiguration new]; audioConfig.numberOfChannels = 2; switch (audioQuality) { - case LFLiveAudioQuality_Default:{ - audioConfig.audioBitrate = LFLiveAudioBitRate_64Kbps; - } - break; - case LFLiveAudioQuality_Low:{ - audioConfig.audioBitrate = LFLiveAudioBitRate_32Kbps; - } - case LFLiveAudioQuality_High:{ - audioConfig.audioBitrate = LFLiveAudioBitRate_96Kbps; - } - case LFLiveAudioQuality_VeryHigh:{ - audioConfig.audioBitrate = LFLiveAudioBitRate_128Kbps; - } - break; - default: - break; + case LFLiveAudioQuality_Low: { + audioConfig.audioBitrate = audioConfig.numberOfChannels == 1 ? LFLiveAudioBitRate_32Kbps : LFLiveAudioBitRate_64Kbps; + audioConfig.audioSampleRate = LFLiveAudioSampleRate_16000Hz; } - audioConfig.audioSampleRate = [self.class isNewThaniPhone6] ? LFLiveAudioSampleRate_48000Hz : LFLiveAudioSampleRate_44100Hz; - + break; + case LFLiveAudioQuality_Medium: { + audioConfig.audioBitrate = LFLiveAudioBitRate_96Kbps; + audioConfig.audioSampleRate = LFLiveAudioSampleRate_44100Hz; + } + break; + case LFLiveAudioQuality_High: { + audioConfig.audioBitrate = LFLiveAudioBitRate_128Kbps; + audioConfig.audioSampleRate = LFLiveAudioSampleRate_44100Hz; + } + break; + case LFLiveAudioQuality_VeryHigh: { + audioConfig.audioBitrate = LFLiveAudioBitRate_128Kbps; + audioConfig.audioSampleRate = LFLiveAudioSampleRate_48000Hz; + } + break; + default:{ + audioConfig.audioBitrate = LFLiveAudioBitRate_96Kbps; + audioConfig.audioSampleRate = LFLiveAudioSampleRate_44100Hz; + } + break; + } + return audioConfig; } -- (instancetype)init{ - if(self = [super init]){ +- (instancetype)init { + if (self = [super init]) { _asc = malloc(2); } return self; } -- (void)dealloc{ - if(_asc) free(_asc); +- (void)dealloc { + if (_asc) free(_asc); } #pragma mark Setter -- (void)setAudioSampleRate:(LFLiveAudioSampleRate)audioSampleRate{ +- (void)setAudioSampleRate:(LFLiveAudioSampleRate)audioSampleRate { _audioSampleRate = audioSampleRate; NSInteger sampleRateIndex = [self sampleRateIndex:audioSampleRate]; - self.asc[0] = 0x10 | ((sampleRateIndex>>1) & 0x3); + self.asc[0] = 0x10 | ((sampleRateIndex>>1) & 0x7); self.asc[1] = ((sampleRateIndex & 0x1)<<7) | ((self.numberOfChannels & 0xF) << 3); } -- (void)setNumberOfChannels:(NSUInteger)numberOfChannels{ +- (void)setNumberOfChannels:(NSUInteger)numberOfChannels { _numberOfChannels = numberOfChannels; NSInteger sampleRateIndex = [self sampleRateIndex:self.audioSampleRate]; - self.asc[0] = 0x10 | ((sampleRateIndex>>1) & 0x3); + self.asc[0] = 0x10 | ((sampleRateIndex>>1) & 0x7); self.asc[1] = ((sampleRateIndex & 0x1)<<7) | ((numberOfChannels & 0xF) << 3); } +- (NSUInteger)bufferLength{ + return 1024*2*self.numberOfChannels; +} #pragma mark -- CustomMethod -- (NSInteger)sampleRateIndex:(NSInteger)frequencyInHz{ +- (NSInteger)sampleRateIndex:(NSInteger)frequencyInHz { NSInteger sampleRateIndex = 0; - switch(frequencyInHz) { - case 96000: - sampleRateIndex = 0; - break; - case 88200: - sampleRateIndex = 1; - break; - case 64000: - sampleRateIndex = 2; - break; - case 48000: - sampleRateIndex = 3; - break; - case 44100: - sampleRateIndex = 4; - break; - case 32000: - sampleRateIndex = 5; - break; - case 24000: - sampleRateIndex = 6; - break; - case 22050: - sampleRateIndex = 7; - break; - case 16000: - sampleRateIndex = 8; - break; - case 12000: - sampleRateIndex = 9; - break; - case 11025: - sampleRateIndex = 10; - break; - case 8000: - sampleRateIndex = 11; - break; - case 7350: - sampleRateIndex = 12; - break; - default: - sampleRateIndex = 15; + switch (frequencyInHz) { + case 96000: + sampleRateIndex = 0; + break; + case 88200: + sampleRateIndex = 1; + break; + case 64000: + sampleRateIndex = 2; + break; + case 48000: + sampleRateIndex = 3; + break; + case 44100: + sampleRateIndex = 4; + break; + case 32000: + sampleRateIndex = 5; + break; + case 24000: + sampleRateIndex = 6; + break; + case 22050: + sampleRateIndex = 7; + break; + case 16000: + sampleRateIndex = 8; + break; + case 12000: + sampleRateIndex = 9; + break; + case 11025: + sampleRateIndex = 10; + break; + case 8000: + sampleRateIndex = 11; + break; + case 7350: + sampleRateIndex = 12; + break; + default: + sampleRateIndex = 15; } return sampleRateIndex; } - -#pragma mark -- DeviceCategory -+(NSString*)deviceName{ - struct utsname systemInfo; - uname(&systemInfo); - - return [NSString stringWithCString:systemInfo.machine - encoding:NSUTF8StringEncoding]; -} - -//@"iPad4,1" on 5th Generation iPad (iPad Air) - Wifi -//@"iPad4,2" on 5th Generation iPad (iPad Air) - Cellular -//@"iPad4,4" on 2nd Generation iPad Mini - Wifi -//@"iPad4,5" on 2nd Generation iPad Mini - Cellular -//@"iPad4,7" on 3rd Generation iPad Mini - Wifi (model A1599) -//@"iPhone7,1" on iPhone 6 Plus -//@"iPhone7,2" on iPhone 6 -//@"iPhone8,1" on iPhone 6S -//@"iPhone8,2" on iPhone 6S Plus - -+(BOOL) isNewThaniPhone6{ - NSString *device = [self deviceName]; - NSLog(@"device %@", device); - if (device == nil) { - return NO; - } - NSArray *array = [device componentsSeparatedByString:@","]; - if (array.count <2) { - return NO; - } - NSString *model = [array objectAtIndex:0]; - NSLog(@"model %@", model); - if ([model hasPrefix:@"iPhone"]) { - NSString *str1 = [model substringFromIndex:[@"iPhone" length]]; - NSUInteger num = [str1 integerValue]; - NSLog(@"num %lu", (unsigned long)num); - if (num > 7) { - return YES; - } - } - - if ([model hasPrefix:@"iPad"]) { - NSString *str1 = [model substringFromIndex:[@"iPad" length]]; - NSUInteger num = [str1 integerValue]; - if (num > 4) { - return YES; - } - } - - return NO; -} - #pragma mark -- Encoder - (void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeObject:@(self.numberOfChannels) forKey:@"numberOfChannels"]; @@ -188,7 +147,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder { return self; } -- (BOOL)isEqual:(id)other{ +- (BOOL)isEqual:(id)other { if (other == self) { return YES; } else if (![super isEqual:other]) { @@ -196,9 +155,9 @@ - (BOOL)isEqual:(id)other{ } else { LFLiveAudioConfiguration *object = other; return object.numberOfChannels == self.numberOfChannels && - object.audioBitrate == self.audioBitrate && - strcmp(object.asc, self.asc) == 0 && - object.audioSampleRate == self.audioSampleRate; + object.audioBitrate == self.audioBitrate && + strcmp(object.asc, self.asc) == 0 && + object.audioSampleRate == self.audioSampleRate; } } @@ -208,25 +167,25 @@ - (NSUInteger)hash { @(_audioSampleRate), [NSString stringWithUTF8String:self.asc], @(_audioBitrate)]; - + for (NSObject *value in values) { hash ^= value.hash; } return hash; } -- (id)copyWithZone:(nullable NSZone *)zone{ +- (id)copyWithZone:(nullable NSZone *)zone { LFLiveAudioConfiguration *other = [self.class defaultConfiguration]; return other; } -- (NSString *)description{ +- (NSString *)description { NSMutableString *desc = @"".mutableCopy; - [desc appendFormat:@"",self]; - [desc appendFormat:@" numberOfChannels:%zi",self.numberOfChannels]; - [desc appendFormat:@" audioSampleRate:%zi",self.audioSampleRate]; - [desc appendFormat:@" audioBitrate:%zi",self.audioBitrate]; - [desc appendFormat:@" audioHeader:%@",[NSString stringWithUTF8String:self.asc]]; + [desc appendFormat:@"", self]; + [desc appendFormat:@" numberOfChannels:%zi", self.numberOfChannels]; + [desc appendFormat:@" audioSampleRate:%zi", self.audioSampleRate]; + [desc appendFormat:@" audioBitrate:%zi", self.audioBitrate]; + [desc appendFormat:@" audioHeader:%@", [NSString stringWithUTF8String:self.asc]]; return desc; } diff --git a/LFLiveKit/configuration/LFLiveVideoConfiguration.h b/LFLiveKit/configuration/LFLiveVideoConfiguration.h index 46e39c07..f0fd7286 100755 --- a/LFLiveKit/configuration/LFLiveVideoConfiguration.h +++ b/LFLiveKit/configuration/LFLiveVideoConfiguration.h @@ -2,15 +2,15 @@ // LFLiveVideoConfiguration.h // LFLiveKit // -// Created by 倾慕 on 16/5/1. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import #import /// 视频分辨率(都是16:9 当此设备不支持当前分辨率,自动降低一级) -typedef NS_ENUM(NSUInteger, LFLiveVideoSessionPreset){ +typedef NS_ENUM (NSUInteger, LFLiveVideoSessionPreset){ /// 低分辨率 LFCaptureSessionPreset360x640 = 0, /// 中分辨率 @@ -20,7 +20,7 @@ typedef NS_ENUM(NSUInteger, LFLiveVideoSessionPreset){ }; /// 视频质量 -typedef NS_ENUM(NSUInteger, LFLiveVideoQuality){ +typedef NS_ENUM (NSUInteger, LFLiveVideoQuality){ /// 分辨率: 360 *640 帧数:15 码率:500Kps LFLiveVideoQuality_Low1 = 0, /// 分辨率: 360 *640 帧数:24 码率:800Kps @@ -43,25 +43,31 @@ typedef NS_ENUM(NSUInteger, LFLiveVideoQuality){ LFLiveVideoQuality_Default = LFLiveVideoQuality_Low2 }; -@interface LFLiveVideoConfiguration : NSObject +@interface LFLiveVideoConfiguration : NSObject /// 默认视频配置 + (instancetype)defaultConfiguration; /// 视频配置(质量) + (instancetype)defaultConfigurationForQuality:(LFLiveVideoQuality)videoQuality; -/// 视频配置(质量 & 方向) -+ (instancetype)defaultConfigurationForQuality:(LFLiveVideoQuality)videoQuality orientation:(UIInterfaceOrientation)orientation; +/// 视频配置(质量 & 是否是横屏) ++ (instancetype)defaultConfigurationForQuality:(LFLiveVideoQuality)videoQuality outputImageOrientation:(UIInterfaceOrientation)outputImageOrientation; #pragma mark - Attribute ///============================================================================= /// @name Attribute ///============================================================================= -/// 视频的分辨率,宽高务必设定为 2 的倍数,否则解码播放时可能出现绿边 +/// 视频的分辨率,宽高务必设定为 2 的倍数,否则解码播放时可能出现绿边(这个videoSizeRespectingAspectRatio设置为YES则可能会改变) @property (nonatomic, assign) CGSize videoSize; +/// 输出图像是否等比例,默认为NO +@property (nonatomic, assign) BOOL videoSizeRespectingAspectRatio; + /// 视频输出方向 -@property (nonatomic, assign) UIInterfaceOrientation orientation; +@property (nonatomic, assign) UIInterfaceOrientation outputImageOrientation; + +/// 自动旋转(这里只支持 left 变 right portrait 变 portraitUpsideDown) +@property (nonatomic, assign) BOOL autorotate; /// 视频的帧率,即 fps @property (nonatomic, assign) NSUInteger videoFrameRate; @@ -88,9 +94,9 @@ typedef NS_ENUM(NSUInteger, LFLiveVideoQuality){ @property (nonatomic, assign) LFLiveVideoSessionPreset sessionPreset; ///< ≈sde3分辨率 -@property (nonatomic, assign,readonly) NSString *avSessionPreset; +@property (nonatomic, assign, readonly) NSString *avSessionPreset; -///< 是否裁剪 -@property (nonatomic, assign,readonly) BOOL isClipVideo; +///< 是否是横屏 +@property (nonatomic, assign, readonly) BOOL landscape; @end diff --git a/LFLiveKit/configuration/LFLiveVideoConfiguration.m b/LFLiveKit/configuration/LFLiveVideoConfiguration.m index 2fd56504..a15a30bb 100755 --- a/LFLiveKit/configuration/LFLiveVideoConfiguration.m +++ b/LFLiveKit/configuration/LFLiveVideoConfiguration.m @@ -2,240 +2,302 @@ // LFLiveVideoConfiguration.m // LFLiveKit // -// Created by 倾慕 on 16/5/1. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFLiveVideoConfiguration.h" #import + @implementation LFLiveVideoConfiguration #pragma mark -- LifeCycle -+ (instancetype)defaultConfiguration{ + ++ (instancetype)defaultConfiguration { LFLiveVideoConfiguration *configuration = [LFLiveVideoConfiguration defaultConfigurationForQuality:LFLiveVideoQuality_Default]; return configuration; } -+ (instancetype)defaultConfigurationForQuality:(LFLiveVideoQuality)videoQuality{ - LFLiveVideoConfiguration *configuration = [LFLiveVideoConfiguration defaultConfigurationForQuality:videoQuality orientation:UIInterfaceOrientationPortrait]; ++ (instancetype)defaultConfigurationForQuality:(LFLiveVideoQuality)videoQuality { + LFLiveVideoConfiguration *configuration = [LFLiveVideoConfiguration defaultConfigurationForQuality:videoQuality outputImageOrientation:UIInterfaceOrientationPortrait]; return configuration; } -+ (instancetype)defaultConfigurationForQuality:(LFLiveVideoQuality)videoQuality orientation:(UIInterfaceOrientation)orientation{ ++ (instancetype)defaultConfigurationForQuality:(LFLiveVideoQuality)videoQuality outputImageOrientation:(UIInterfaceOrientation)outputImageOrientation { LFLiveVideoConfiguration *configuration = [LFLiveVideoConfiguration new]; switch (videoQuality) { - case LFLiveVideoQuality_Low1: - { - configuration.sessionPreset = LFCaptureSessionPreset360x640; - configuration.videoFrameRate = 15; - configuration.videoMaxFrameRate = 15; - configuration.videoMinFrameRate = 10; - configuration.videoBitRate = 500 * 1000; - configuration.videoMaxBitRate = 600 * 1000; - configuration.videoMinBitRate = 400 * 1000; - configuration.videoSize = CGSizeMake(360, 640); - } - break; - case LFLiveVideoQuality_Low2: - { - configuration.sessionPreset = LFCaptureSessionPreset360x640; - configuration.videoFrameRate = 24; - configuration.videoMaxFrameRate = 24; - configuration.videoMinFrameRate = 12; - configuration.videoBitRate = 600 * 1000; - configuration.videoMaxBitRate = 720 * 1000; - configuration.videoMinBitRate = 500 * 1000; - configuration.videoSize = CGSizeMake(360, 640); - } - break; - case LFLiveVideoQuality_Low3: - { - configuration.sessionPreset = LFCaptureSessionPreset360x640; - configuration.videoFrameRate = 30; - configuration.videoMaxFrameRate = 30; - configuration.videoMinFrameRate = 15; - configuration.videoBitRate = 800 * 1000; - configuration.videoMaxBitRate = 960 * 1000; - configuration.videoMinBitRate = 600 * 1000; - configuration.videoSize = CGSizeMake(360, 640); - } - break; - case LFLiveVideoQuality_Medium1: - { - configuration.sessionPreset = LFCaptureSessionPreset540x960; - configuration.videoFrameRate = 15; - configuration.videoMaxFrameRate = 15; - configuration.videoMinFrameRate = 10; - configuration.videoBitRate = 800 * 1000; - configuration.videoMaxBitRate = 960 * 1000; - configuration.videoMinBitRate = 500 * 1000; - configuration.videoSize = CGSizeMake(540, 960); - } - break; - case LFLiveVideoQuality_Medium2: - { - configuration.sessionPreset = LFCaptureSessionPreset540x960; - configuration.videoFrameRate = 24; - configuration.videoMaxFrameRate = 24; - configuration.videoMinFrameRate = 12; - configuration.videoBitRate = 800 * 1000; - configuration.videoMaxBitRate = 960 * 1000; - configuration.videoMinBitRate = 500 * 1000; - configuration.videoSize = CGSizeMake(540, 960); - } - break; - case LFLiveVideoQuality_Medium3: - { - configuration.sessionPreset = LFCaptureSessionPreset540x960; - configuration.videoFrameRate = 30; - configuration.videoMaxFrameRate = 30; - configuration.videoMinFrameRate = 15; - configuration.videoBitRate = 1000 * 1000; - configuration.videoMaxBitRate = 1200 * 1000; - configuration.videoMinBitRate = 500 * 1000; - configuration.videoSize = CGSizeMake(540, 960); - } - break; - case LFLiveVideoQuality_High1: - { - configuration.sessionPreset = LFCaptureSessionPreset720x1280; - configuration.videoFrameRate = 15; - configuration.videoMaxFrameRate = 15; - configuration.videoMinFrameRate = 10; - configuration.videoBitRate = 1000 * 1000; - configuration.videoMaxBitRate = 1200 * 1000; - configuration.videoMinBitRate = 500 * 1000; - configuration.videoSize = CGSizeMake(720, 1280); - } - break; - case LFLiveVideoQuality_High2: - { - configuration.sessionPreset = LFCaptureSessionPreset720x1280; - configuration.videoFrameRate = 24; - configuration.videoMaxFrameRate = 24; - configuration.videoMinFrameRate = 12; - configuration.videoBitRate = 1200 * 1000; - configuration.videoMaxBitRate = 1440 * 1000; - configuration.videoMinBitRate = 800 * 1000; - configuration.videoSize = CGSizeMake(720, 1280); - } - break; - case LFLiveVideoQuality_High3: - { - configuration.sessionPreset = LFCaptureSessionPreset720x1280; - configuration.videoFrameRate = 30; - configuration.videoMaxFrameRate = 30; - configuration.videoMinFrameRate = 15; - configuration.videoBitRate = 1200 * 1000; - configuration.videoMaxBitRate = 1440 * 1000; - configuration.videoMinBitRate = 500 * 1000; - configuration.videoSize = CGSizeMake(720, 1280); - } - break; - default: - break; + case LFLiveVideoQuality_Low1:{ + configuration.sessionPreset = LFCaptureSessionPreset360x640; + configuration.videoFrameRate = 15; + configuration.videoMaxFrameRate = 15; + configuration.videoMinFrameRate = 10; + configuration.videoBitRate = 500 * 1000; + configuration.videoMaxBitRate = 600 * 1000; + configuration.videoMinBitRate = 400 * 1000; + configuration.videoSize = CGSizeMake(360, 640); + } + break; + case LFLiveVideoQuality_Low2:{ + configuration.sessionPreset = LFCaptureSessionPreset360x640; + configuration.videoFrameRate = 24; + configuration.videoMaxFrameRate = 24; + configuration.videoMinFrameRate = 12; + configuration.videoBitRate = 600 * 1000; + configuration.videoMaxBitRate = 720 * 1000; + configuration.videoMinBitRate = 500 * 1000; + configuration.videoSize = CGSizeMake(360, 640); + } + break; + case LFLiveVideoQuality_Low3: { + configuration.sessionPreset = LFCaptureSessionPreset360x640; + configuration.videoFrameRate = 30; + configuration.videoMaxFrameRate = 30; + configuration.videoMinFrameRate = 15; + configuration.videoBitRate = 800 * 1000; + configuration.videoMaxBitRate = 960 * 1000; + configuration.videoMinBitRate = 600 * 1000; + configuration.videoSize = CGSizeMake(360, 640); + } + break; + case LFLiveVideoQuality_Medium1:{ + configuration.sessionPreset = LFCaptureSessionPreset540x960; + configuration.videoFrameRate = 15; + configuration.videoMaxFrameRate = 15; + configuration.videoMinFrameRate = 10; + configuration.videoBitRate = 800 * 1000; + configuration.videoMaxBitRate = 960 * 1000; + configuration.videoMinBitRate = 500 * 1000; + configuration.videoSize = CGSizeMake(540, 960); + } + break; + case LFLiveVideoQuality_Medium2:{ + configuration.sessionPreset = LFCaptureSessionPreset540x960; + configuration.videoFrameRate = 24; + configuration.videoMaxFrameRate = 24; + configuration.videoMinFrameRate = 12; + configuration.videoBitRate = 800 * 1000; + configuration.videoMaxBitRate = 960 * 1000; + configuration.videoMinBitRate = 500 * 1000; + configuration.videoSize = CGSizeMake(540, 960); + } + break; + case LFLiveVideoQuality_Medium3:{ + configuration.sessionPreset = LFCaptureSessionPreset540x960; + configuration.videoFrameRate = 30; + configuration.videoMaxFrameRate = 30; + configuration.videoMinFrameRate = 15; + configuration.videoBitRate = 1000 * 1000; + configuration.videoMaxBitRate = 1200 * 1000; + configuration.videoMinBitRate = 500 * 1000; + configuration.videoSize = CGSizeMake(540, 960); + } + break; + case LFLiveVideoQuality_High1:{ + configuration.sessionPreset = LFCaptureSessionPreset720x1280; + configuration.videoFrameRate = 15; + configuration.videoMaxFrameRate = 15; + configuration.videoMinFrameRate = 10; + configuration.videoBitRate = 1000 * 1000; + configuration.videoMaxBitRate = 1200 * 1000; + configuration.videoMinBitRate = 500 * 1000; + configuration.videoSize = CGSizeMake(720, 1280); + } + break; + case LFLiveVideoQuality_High2:{ + configuration.sessionPreset = LFCaptureSessionPreset720x1280; + configuration.videoFrameRate = 24; + configuration.videoMaxFrameRate = 24; + configuration.videoMinFrameRate = 12; + configuration.videoBitRate = 1200 * 1000; + configuration.videoMaxBitRate = 1440 * 1000; + configuration.videoMinBitRate = 800 * 1000; + configuration.videoSize = CGSizeMake(720, 1280); + } + break; + case LFLiveVideoQuality_High3:{ + configuration.sessionPreset = LFCaptureSessionPreset720x1280; + configuration.videoFrameRate = 30; + configuration.videoMaxFrameRate = 30; + configuration.videoMinFrameRate = 15; + configuration.videoBitRate = 1200 * 1000; + configuration.videoMaxBitRate = 1440 * 1000; + configuration.videoMinBitRate = 500 * 1000; + configuration.videoSize = CGSizeMake(720, 1280); + } + break; + default: + break; } configuration.sessionPreset = [configuration supportSessionPreset:configuration.sessionPreset]; configuration.videoMaxKeyframeInterval = configuration.videoFrameRate*2; - configuration.orientation = orientation; + configuration.outputImageOrientation = outputImageOrientation; CGSize size = configuration.videoSize; - if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown){ - configuration.videoSize = CGSizeMake(size.width, size.height); - }else{ + if(configuration.landscape) { configuration.videoSize = CGSizeMake(size.height, size.width); + } else { + configuration.videoSize = CGSizeMake(size.width, size.height); } return configuration; + } #pragma mark -- Setter Getter -- (NSString*)avSessionPreset{ +- (NSString *)avSessionPreset { NSString *avSessionPreset = nil; switch (self.sessionPreset) { - case LFCaptureSessionPreset360x640: - { - avSessionPreset = AVCaptureSessionPreset640x480; - } - break; - case LFCaptureSessionPreset540x960: - { - avSessionPreset = AVCaptureSessionPresetiFrame960x540; - } - break; - case LFCaptureSessionPreset720x1280: - { - avSessionPreset = AVCaptureSessionPreset1280x720; - } - break; - default:{ - avSessionPreset = AVCaptureSessionPreset640x480; - } - break; + case LFCaptureSessionPreset360x640:{ + avSessionPreset = AVCaptureSessionPreset640x480; + } + break; + case LFCaptureSessionPreset540x960:{ + avSessionPreset = AVCaptureSessionPresetiFrame960x540; + } + break; + case LFCaptureSessionPreset720x1280:{ + avSessionPreset = AVCaptureSessionPreset1280x720; + } + break; + default: { + avSessionPreset = AVCaptureSessionPreset640x480; + } + break; } return avSessionPreset; } -- (void)setVideoMaxBitRate:(NSUInteger)videoMaxBitRate{ - if(videoMaxBitRate <= _videoBitRate) return; +- (BOOL)landscape{ + return (self.outputImageOrientation == UIInterfaceOrientationLandscapeLeft || self.outputImageOrientation == UIInterfaceOrientationLandscapeRight) ? YES : NO; +} + +- (CGSize)videoSize{ + if(_videoSizeRespectingAspectRatio){ + return self.aspectRatioVideoSize; + } + return _videoSize; +} + +- (void)setVideoMaxBitRate:(NSUInteger)videoMaxBitRate { + if (videoMaxBitRate <= _videoBitRate) return; _videoMaxBitRate = videoMaxBitRate; } -- (void)setVideoMinBitRate:(NSUInteger)videoMinBitRate{ - if(videoMinBitRate >= _videoBitRate) return; +- (void)setVideoMinBitRate:(NSUInteger)videoMinBitRate { + if (videoMinBitRate >= _videoBitRate) return; _videoMinBitRate = videoMinBitRate; } -- (void)setVideoMaxFrameRate:(NSUInteger)videoMaxFrameRate{ - if(videoMaxFrameRate <= _videoFrameRate) return; +- (void)setVideoMaxFrameRate:(NSUInteger)videoMaxFrameRate { + if (videoMaxFrameRate <= _videoFrameRate) return; _videoMaxFrameRate = videoMaxFrameRate; } -- (void)setVideoMinFrameRate:(NSUInteger)videoMinFrameRate{ - if(videoMinFrameRate >= _videoFrameRate) return; +- (void)setVideoMinFrameRate:(NSUInteger)videoMinFrameRate { + if (videoMinFrameRate >= _videoFrameRate) return; _videoMinFrameRate = videoMinFrameRate; } +- (void)setSessionPreset:(LFLiveVideoSessionPreset)sessionPreset{ + _sessionPreset = sessionPreset; + _sessionPreset = [self supportSessionPreset:sessionPreset]; +} #pragma mark -- Custom Method -- (LFLiveVideoSessionPreset)supportSessionPreset:(LFLiveVideoSessionPreset)sessionPreset{ - NSString *avSessionPreset = [self avSessionPreset]; +- (LFLiveVideoSessionPreset)supportSessionPreset:(LFLiveVideoSessionPreset)sessionPreset { AVCaptureSession *session = [[AVCaptureSession alloc] init]; + AVCaptureDevice *inputCamera; + NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; + for (AVCaptureDevice *device in devices){ + if ([device position] == AVCaptureDevicePositionFront){ + inputCamera = device; + } + } + AVCaptureDeviceInput *videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:inputCamera error:nil]; - if(![session canSetSessionPreset:avSessionPreset]){ - if(sessionPreset == LFCaptureSessionPreset720x1280){ + if ([session canAddInput:videoInput]){ + [session addInput:videoInput]; + } + + if (![session canSetSessionPreset:self.avSessionPreset]) { + if (sessionPreset == LFCaptureSessionPreset720x1280) { sessionPreset = LFCaptureSessionPreset540x960; - if(![session canSetSessionPreset:avSessionPreset]){ + if (![session canSetSessionPreset:self.avSessionPreset]) { sessionPreset = LFCaptureSessionPreset360x640; } - }else if(sessionPreset == LFCaptureSessionPreset540x960){ + } else if (sessionPreset == LFCaptureSessionPreset540x960) { sessionPreset = LFCaptureSessionPreset360x640; } } return sessionPreset; } -- (BOOL)isClipVideo{ - return self.sessionPreset == LFCaptureSessionPreset360x640 ? YES : NO; +- (CGSize)captureOutVideoSize{ + CGSize videoSize = CGSizeZero; + switch (_sessionPreset) { + case LFCaptureSessionPreset360x640:{ + videoSize = CGSizeMake(360, 640); + } + break; + case LFCaptureSessionPreset540x960:{ + videoSize = CGSizeMake(540, 960); + } + break; + case LFCaptureSessionPreset720x1280:{ + videoSize = CGSizeMake(720, 1280); + } + break; + + default:{ + videoSize = CGSizeMake(360, 640); + } + break; + } + + if (self.landscape){ + return CGSizeMake(videoSize.height, videoSize.width); + } + return videoSize; +} + +- (CGSize)aspectRatioVideoSize{ + CGSize size = AVMakeRectWithAspectRatioInsideRect(self.captureOutVideoSize, CGRectMake(0, 0, _videoSize.width, _videoSize.height)).size; + NSInteger width = ceil(size.width); + NSInteger height = ceil(size.height); + if(width %2 != 0) width = width - 1; + if(height %2 != 0) height = height - 1; + return CGSizeMake(width, height); } #pragma mark -- encoder - (void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeObject:[NSValue valueWithCGSize:self.videoSize] forKey:@"videoSize"]; [aCoder encodeObject:@(self.videoFrameRate) forKey:@"videoFrameRate"]; + [aCoder encodeObject:@(self.videoMaxFrameRate) forKey:@"videoMaxFrameRate"]; + [aCoder encodeObject:@(self.videoMinFrameRate) forKey:@"videoMinFrameRate"]; [aCoder encodeObject:@(self.videoMaxKeyframeInterval) forKey:@"videoMaxKeyframeInterval"]; [aCoder encodeObject:@(self.videoBitRate) forKey:@"videoBitRate"]; + [aCoder encodeObject:@(self.videoMaxBitRate) forKey:@"videoMaxBitRate"]; + [aCoder encodeObject:@(self.videoMinBitRate) forKey:@"videoMinBitRate"]; [aCoder encodeObject:@(self.sessionPreset) forKey:@"sessionPreset"]; - [aCoder encodeObject:@(self.orientation) forKey:@"orientation"]; + [aCoder encodeObject:@(self.outputImageOrientation) forKey:@"outputImageOrientation"]; + [aCoder encodeObject:@(self.autorotate) forKey:@"autorotate"]; + [aCoder encodeObject:@(self.videoSizeRespectingAspectRatio) forKey:@"videoSizeRespectingAspectRatio"]; } - (id)initWithCoder:(NSCoder *)aDecoder { self = [super init]; _videoSize = [[aDecoder decodeObjectForKey:@"videoSize"] CGSizeValue]; _videoFrameRate = [[aDecoder decodeObjectForKey:@"videoFrameRate"] unsignedIntegerValue]; + _videoMaxFrameRate = [[aDecoder decodeObjectForKey:@"videoMaxFrameRate"] unsignedIntegerValue]; + _videoMinFrameRate = [[aDecoder decodeObjectForKey:@"videoMinFrameRate"] unsignedIntegerValue]; _videoMaxKeyframeInterval = [[aDecoder decodeObjectForKey:@"videoMaxKeyframeInterval"] unsignedIntegerValue]; _videoBitRate = [[aDecoder decodeObjectForKey:@"videoBitRate"] unsignedIntegerValue]; + _videoMaxBitRate = [[aDecoder decodeObjectForKey:@"videoMaxBitRate"] unsignedIntegerValue]; + _videoMinBitRate = [[aDecoder decodeObjectForKey:@"videoMinBitRate"] unsignedIntegerValue]; _sessionPreset = [[aDecoder decodeObjectForKey:@"sessionPreset"] unsignedIntegerValue]; - _orientation = [[aDecoder decodeObjectForKey:@"orientation"] unsignedIntegerValue]; + _outputImageOrientation = [[aDecoder decodeObjectForKey:@"outputImageOrientation"] unsignedIntegerValue]; + _autorotate = [[aDecoder decodeObjectForKey:@"autorotate"] boolValue]; + _videoSizeRespectingAspectRatio = [[aDecoder decodeObjectForKey:@"videoSizeRespectingAspectRatio"] unsignedIntegerValue]; return self; } @@ -249,60 +311,62 @@ - (NSUInteger)hash { @(self.videoBitRate), @(self.videoMaxBitRate), @(self.videoMinBitRate), - @(self.isClipVideo), self.avSessionPreset, @(self.sessionPreset), - @(self.orientation),]; - + @(self.outputImageOrientation), + @(self.autorotate), + @(self.videoSizeRespectingAspectRatio)]; + for (NSObject *value in values) { hash ^= value.hash; } return hash; } -- (BOOL)isEqual:(id)other -{ +- (BOOL)isEqual:(id)other { if (other == self) { return YES; } else if (![super isEqual:other]) { return NO; } else { LFLiveVideoConfiguration *object = other; - return CGSizeEqualToSize(object.videoSize, self.videoSize) && - object.videoFrameRate == self.videoFrameRate && - object.videoMaxFrameRate == self.videoMaxFrameRate && - object.videoMinFrameRate == self.videoMinFrameRate && - object.videoMaxKeyframeInterval == self.videoMaxKeyframeInterval && - 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.orientation == self.orientation; + return CGSizeEqualToSize(object.videoSize, self.videoSize) && + object.videoFrameRate == self.videoFrameRate && + object.videoMaxFrameRate == self.videoMaxFrameRate && + object.videoMinFrameRate == self.videoMinFrameRate && + object.videoMaxKeyframeInterval == self.videoMaxKeyframeInterval && + object.videoBitRate == self.videoBitRate && + object.videoMaxBitRate == self.videoMaxBitRate && + object.videoMinBitRate == self.videoMinBitRate && + [object.avSessionPreset isEqualToString:self.avSessionPreset] && + object.sessionPreset == self.sessionPreset && + object.outputImageOrientation == self.outputImageOrientation && + object.autorotate == self.autorotate && + object.videoSizeRespectingAspectRatio == self.videoSizeRespectingAspectRatio; } } -- (id)copyWithZone:(nullable NSZone *)zone{ +- (id)copyWithZone:(nullable NSZone *)zone { LFLiveVideoConfiguration *other = [self.class defaultConfiguration]; return other; } -- (NSString *)description{ +- (NSString *)description { NSMutableString *desc = @"".mutableCopy; - [desc appendFormat:@"",self]; - [desc appendFormat:@" videoSize:%@",NSStringFromCGSize(self.videoSize)]; - [desc appendFormat:@" videoFrameRate:%zi",self.videoFrameRate]; - [desc appendFormat:@" videoMaxFrameRate:%zi",self.videoMaxFrameRate]; - [desc appendFormat:@" videoMinFrameRate:%zi",self.videoMinFrameRate]; - [desc appendFormat:@" videoMaxKeyframeInterval:%zi",self.videoMaxKeyframeInterval]; - [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:@" orientation:%zi",self.orientation]; + [desc appendFormat:@"", self]; + [desc appendFormat:@" videoSize:%@", NSStringFromCGSize(self.videoSize)]; + [desc appendFormat:@" videoSizeRespectingAspectRatio:%zi",self.videoSizeRespectingAspectRatio]; + [desc appendFormat:@" videoFrameRate:%zi", self.videoFrameRate]; + [desc appendFormat:@" videoMaxFrameRate:%zi", self.videoMaxFrameRate]; + [desc appendFormat:@" videoMinFrameRate:%zi", self.videoMinFrameRate]; + [desc appendFormat:@" videoMaxKeyframeInterval:%zi", self.videoMaxKeyframeInterval]; + [desc appendFormat:@" videoBitRate:%zi", self.videoBitRate]; + [desc appendFormat:@" videoMaxBitRate:%zi", self.videoMaxBitRate]; + [desc appendFormat:@" videoMinBitRate:%zi", self.videoMinBitRate]; + [desc appendFormat:@" avSessionPreset:%@", self.avSessionPreset]; + [desc appendFormat:@" sessionPreset:%zi", self.sessionPreset]; + [desc appendFormat:@" outputImageOrientation:%zi", self.outputImageOrientation]; + [desc appendFormat:@" autorotate:%zi", self.autorotate]; return desc; } diff --git a/LFLiveKit/filter/LFGPUImageBeautyFilter.h b/LFLiveKit/filter/LFGPUImageBeautyFilter.h index d698db18..03211585 100755 --- a/LFLiveKit/filter/LFGPUImageBeautyFilter.h +++ b/LFLiveKit/filter/LFGPUImageBeautyFilter.h @@ -1,4 +1,8 @@ -#import "GPUImageFilter.h" +#if __has_include() +#import +#else +#import "GPUImage.h" +#endif @interface LFGPUImageBeautyFilter : GPUImageFilter { } diff --git a/LFLiveKit/filter/LFGPUImageBeautyFilter.m b/LFLiveKit/filter/LFGPUImageBeautyFilter.m index 335f1cc9..dafae4d9 100755 --- a/LFLiveKit/filter/LFGPUImageBeautyFilter.m +++ b/LFLiveKit/filter/LFGPUImageBeautyFilter.m @@ -2,237 +2,233 @@ #if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE NSString *const kLFGPUImageBeautyFragmentShaderString = SHADER_STRING -( - varying highp vec2 textureCoordinate; - - uniform sampler2D inputImageTexture; - - uniform highp vec2 singleStepOffset; - uniform highp vec4 params; - uniform highp float brightness; - - const highp vec3 W = vec3(0.299,0.587,0.114); - const highp mat3 saturateMatrix = mat3( - 1.1102,-0.0598,-0.061, - -0.0774,1.0826,-0.1186, - -0.0228,-0.0228,1.1772); - highp vec2 blurCoordinates[24]; - - highp float hardLight(highp float color) { - if(color <= 0.5) + ( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform highp vec2 singleStepOffset; + uniform highp vec4 params; + uniform highp float brightness; + + const highp vec3 W = vec3(0.299, 0.587, 0.114); + const highp mat3 saturateMatrix = mat3( + 1.1102, -0.0598, -0.061, + -0.0774, 1.0826, -0.1186, + -0.0228, -0.0228, 1.1772); + highp vec2 blurCoordinates[24]; + + highp float hardLight(highp float color) { + if (color <= 0.5) color = color * color * 2.0; else color = 1.0 - ((1.0 - color)*(1.0 - color) * 2.0); return color; } - - void main() - { - highp vec3 centralColor = texture2D(inputImageTexture, textureCoordinate).rgb; - blurCoordinates[0] = textureCoordinate.xy + singleStepOffset * vec2(0.0, -10.0); - blurCoordinates[1] = textureCoordinate.xy + singleStepOffset * vec2(0.0, 10.0); - blurCoordinates[2] = textureCoordinate.xy + singleStepOffset * vec2(-10.0, 0.0); - blurCoordinates[3] = textureCoordinate.xy + singleStepOffset * vec2(10.0, 0.0); - blurCoordinates[4] = textureCoordinate.xy + singleStepOffset * vec2(5.0, -8.0); - blurCoordinates[5] = textureCoordinate.xy + singleStepOffset * vec2(5.0, 8.0); - blurCoordinates[6] = textureCoordinate.xy + singleStepOffset * vec2(-5.0, 8.0); - blurCoordinates[7] = textureCoordinate.xy + singleStepOffset * vec2(-5.0, -8.0); - blurCoordinates[8] = textureCoordinate.xy + singleStepOffset * vec2(8.0, -5.0); - blurCoordinates[9] = textureCoordinate.xy + singleStepOffset * vec2(8.0, 5.0); - blurCoordinates[10] = textureCoordinate.xy + singleStepOffset * vec2(-8.0, 5.0); - blurCoordinates[11] = textureCoordinate.xy + singleStepOffset * vec2(-8.0, -5.0); - blurCoordinates[12] = textureCoordinate.xy + singleStepOffset * vec2(0.0, -6.0); - blurCoordinates[13] = textureCoordinate.xy + singleStepOffset * vec2(0.0, 6.0); - blurCoordinates[14] = textureCoordinate.xy + singleStepOffset * vec2(6.0, 0.0); - blurCoordinates[15] = textureCoordinate.xy + singleStepOffset * vec2(-6.0, 0.0); - blurCoordinates[16] = textureCoordinate.xy + singleStepOffset * vec2(-4.0, -4.0); - blurCoordinates[17] = textureCoordinate.xy + singleStepOffset * vec2(-4.0, 4.0); - blurCoordinates[18] = textureCoordinate.xy + singleStepOffset * vec2(4.0, -4.0); - blurCoordinates[19] = textureCoordinate.xy + singleStepOffset * vec2(4.0, 4.0); - blurCoordinates[20] = textureCoordinate.xy + singleStepOffset * vec2(-2.0, -2.0); - blurCoordinates[21] = textureCoordinate.xy + singleStepOffset * vec2(-2.0, 2.0); - blurCoordinates[22] = textureCoordinate.xy + singleStepOffset * vec2(2.0, -2.0); - blurCoordinates[23] = textureCoordinate.xy + singleStepOffset * vec2(2.0, 2.0); - - highp float sampleColor = centralColor.g * 22.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[0]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[1]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[2]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[3]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[4]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[5]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[6]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[7]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[8]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[9]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[10]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[11]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[12]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[13]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[14]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[15]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[16]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[17]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[18]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[19]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[20]).g * 3.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[21]).g * 3.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[22]).g * 3.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[23]).g * 3.0; - - sampleColor = sampleColor / 62.0; - - highp float highPass = centralColor.g - sampleColor + 0.5; - - for(int i = 0; i < 5;i++) - { - highPass = hardLight(highPass); - } - highp float lumance = dot(centralColor, W); - - highp float alpha = pow(lumance, params.r); - - highp vec3 smoothColor = centralColor + (centralColor-vec3(highPass))*alpha*0.1; - - smoothColor.r = clamp(pow(smoothColor.r, params.g),0.0,1.0); - smoothColor.g = clamp(pow(smoothColor.g, params.g),0.0,1.0); - smoothColor.b = clamp(pow(smoothColor.b, params.g),0.0,1.0); - - highp vec3 lvse = vec3(1.0)-(vec3(1.0)-smoothColor)*(vec3(1.0)-centralColor); - highp vec3 bianliang = max(smoothColor, centralColor); - highp vec3 rouguang = 2.0*centralColor*smoothColor + centralColor*centralColor - 2.0*centralColor*centralColor*smoothColor; - - gl_FragColor = vec4(mix(centralColor, lvse, alpha), 1.0); - gl_FragColor.rgb = mix(gl_FragColor.rgb, bianliang, alpha); - gl_FragColor.rgb = mix(gl_FragColor.rgb, rouguang, params.b); - - highp vec3 satcolor = gl_FragColor.rgb * saturateMatrix; - gl_FragColor.rgb = mix(gl_FragColor.rgb, satcolor, params.a); - gl_FragColor.rgb = vec3(gl_FragColor.rgb + vec3(brightness)); - } -); + + void main(){ + highp vec3 centralColor = texture2D(inputImageTexture, textureCoordinate).rgb; + blurCoordinates[0] = textureCoordinate.xy + singleStepOffset * vec2(0.0, -10.0); + blurCoordinates[1] = textureCoordinate.xy + singleStepOffset * vec2(0.0, 10.0); + blurCoordinates[2] = textureCoordinate.xy + singleStepOffset * vec2(-10.0, 0.0); + blurCoordinates[3] = textureCoordinate.xy + singleStepOffset * vec2(10.0, 0.0); + blurCoordinates[4] = textureCoordinate.xy + singleStepOffset * vec2(5.0, -8.0); + blurCoordinates[5] = textureCoordinate.xy + singleStepOffset * vec2(5.0, 8.0); + blurCoordinates[6] = textureCoordinate.xy + singleStepOffset * vec2(-5.0, 8.0); + blurCoordinates[7] = textureCoordinate.xy + singleStepOffset * vec2(-5.0, -8.0); + blurCoordinates[8] = textureCoordinate.xy + singleStepOffset * vec2(8.0, -5.0); + blurCoordinates[9] = textureCoordinate.xy + singleStepOffset * vec2(8.0, 5.0); + blurCoordinates[10] = textureCoordinate.xy + singleStepOffset * vec2(-8.0, 5.0); + blurCoordinates[11] = textureCoordinate.xy + singleStepOffset * vec2(-8.0, -5.0); + blurCoordinates[12] = textureCoordinate.xy + singleStepOffset * vec2(0.0, -6.0); + blurCoordinates[13] = textureCoordinate.xy + singleStepOffset * vec2(0.0, 6.0); + blurCoordinates[14] = textureCoordinate.xy + singleStepOffset * vec2(6.0, 0.0); + blurCoordinates[15] = textureCoordinate.xy + singleStepOffset * vec2(-6.0, 0.0); + blurCoordinates[16] = textureCoordinate.xy + singleStepOffset * vec2(-4.0, -4.0); + blurCoordinates[17] = textureCoordinate.xy + singleStepOffset * vec2(-4.0, 4.0); + blurCoordinates[18] = textureCoordinate.xy + singleStepOffset * vec2(4.0, -4.0); + blurCoordinates[19] = textureCoordinate.xy + singleStepOffset * vec2(4.0, 4.0); + blurCoordinates[20] = textureCoordinate.xy + singleStepOffset * vec2(-2.0, -2.0); + blurCoordinates[21] = textureCoordinate.xy + singleStepOffset * vec2(-2.0, 2.0); + blurCoordinates[22] = textureCoordinate.xy + singleStepOffset * vec2(2.0, -2.0); + blurCoordinates[23] = textureCoordinate.xy + singleStepOffset * vec2(2.0, 2.0); + + highp float sampleColor = centralColor.g * 22.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[0]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[1]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[2]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[3]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[4]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[5]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[6]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[7]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[8]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[9]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[10]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[11]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[12]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[13]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[14]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[15]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[16]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[17]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[18]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[19]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[20]).g * 3.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[21]).g * 3.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[22]).g * 3.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[23]).g * 3.0; + + sampleColor = sampleColor / 62.0; + + highp float highPass = centralColor.g - sampleColor + 0.5; + + for (int i = 0; i < 5; i++) { + highPass = hardLight(highPass); + } + highp float lumance = dot(centralColor, W); + + highp float alpha = pow(lumance, params.r); + + highp vec3 smoothColor = centralColor + (centralColor-vec3(highPass))*alpha*0.1; + + smoothColor.r = clamp(pow(smoothColor.r, params.g), 0.0, 1.0); + smoothColor.g = clamp(pow(smoothColor.g, params.g), 0.0, 1.0); + smoothColor.b = clamp(pow(smoothColor.b, params.g), 0.0, 1.0); + + highp vec3 lvse = vec3(1.0)-(vec3(1.0)-smoothColor)*(vec3(1.0)-centralColor); + highp vec3 bianliang = max(smoothColor, centralColor); + highp vec3 rouguang = 2.0*centralColor*smoothColor + centralColor*centralColor - 2.0*centralColor*centralColor*smoothColor; + + gl_FragColor = vec4(mix(centralColor, lvse, alpha), 1.0); + gl_FragColor.rgb = mix(gl_FragColor.rgb, bianliang, alpha); + gl_FragColor.rgb = mix(gl_FragColor.rgb, rouguang, params.b); + + highp vec3 satcolor = gl_FragColor.rgb * saturateMatrix; + gl_FragColor.rgb = mix(gl_FragColor.rgb, satcolor, params.a); + gl_FragColor.rgb = vec3(gl_FragColor.rgb + vec3(brightness)); +} + + ); #else NSString *const kLFGPUImageBeautyFragmentShaderString = SHADER_STRING -( - varying vec2 textureCoordinate; - - uniform sampler2D inputImageTexture; - - uniform mediump vec2 singleStepOffset; - uniform mediump vec4 params; - uniform mediump float brightness; - const mediump mat3 saturateMatrix = mat3( - 1.1102,-0.0598,-0.061, - -0.0774,1.0826,-0.1186, - -0.0228,-0.0228,1.1772); - const mediump vec3 W = vec3(0.299,0.587,0.114); - mediump vec2 blurCoordinates[24]; - - mediump float hardLight(mediump float color) -{ - if(color <= 0.5) + ( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform mediump vec2 singleStepOffset; + uniform mediump vec4 params; + uniform mediump float brightness; + const mediump mat3 saturateMatrix = mat3( + 1.1102, -0.0598, -0.061, + -0.0774, 1.0826, -0.1186, + -0.0228, -0.0228, 1.1772); + const mediump vec3 W = vec3(0.299, 0.587, 0.114); + mediump vec2 blurCoordinates[24]; + + mediump float hardLight(mediump float color){ + if (color <= 0.5) color = color * color * 2.0; else color = 1.0 - ((1.0 - color)*(1.0 - color) * 2.0); return color; } - - void main() - { - mediump vec3 centralColor = texture2D(inputImageTexture, textureCoordinate).rgb; - blurCoordinates[0] = textureCoordinate.xy + singleStepOffset * vec2(0.0, -10.0); - blurCoordinates[1] = textureCoordinate.xy + singleStepOffset * vec2(0.0, 10.0); - blurCoordinates[2] = textureCoordinate.xy + singleStepOffset * vec2(-10.0, 0.0); - blurCoordinates[3] = textureCoordinate.xy + singleStepOffset * vec2(10.0, 0.0); - blurCoordinates[4] = textureCoordinate.xy + singleStepOffset * vec2(5.0, -8.0); - blurCoordinates[5] = textureCoordinate.xy + singleStepOffset * vec2(5.0, 8.0); - blurCoordinates[6] = textureCoordinate.xy + singleStepOffset * vec2(-5.0, 8.0); - blurCoordinates[7] = textureCoordinate.xy + singleStepOffset * vec2(-5.0, -8.0); - blurCoordinates[8] = textureCoordinate.xy + singleStepOffset * vec2(8.0, -5.0); - blurCoordinates[9] = textureCoordinate.xy + singleStepOffset * vec2(8.0, 5.0); - blurCoordinates[10] = textureCoordinate.xy + singleStepOffset * vec2(-8.0, 5.0); - blurCoordinates[11] = textureCoordinate.xy + singleStepOffset * vec2(-8.0, -5.0); - blurCoordinates[12] = textureCoordinate.xy + singleStepOffset * vec2(0.0, -6.0); - blurCoordinates[13] = textureCoordinate.xy + singleStepOffset * vec2(0.0, 6.0); - blurCoordinates[14] = textureCoordinate.xy + singleStepOffset * vec2(6.0, 0.0); - blurCoordinates[15] = textureCoordinate.xy + singleStepOffset * vec2(-6.0, 0.0); - blurCoordinates[16] = textureCoordinate.xy + singleStepOffset * vec2(-4.0, -4.0); - blurCoordinates[17] = textureCoordinate.xy + singleStepOffset * vec2(-4.0, 4.0); - blurCoordinates[18] = textureCoordinate.xy + singleStepOffset * vec2(4.0, -4.0); - blurCoordinates[19] = textureCoordinate.xy + singleStepOffset * vec2(4.0, 4.0); - blurCoordinates[20] = textureCoordinate.xy + singleStepOffset * vec2(-2.0, -2.0); - blurCoordinates[21] = textureCoordinate.xy + singleStepOffset * vec2(-2.0, 2.0); - blurCoordinates[22] = textureCoordinate.xy + singleStepOffset * vec2(2.0, -2.0); - blurCoordinates[23] = textureCoordinate.xy + singleStepOffset * vec2(2.0, 2.0); - - mediump float sampleColor = centralColor.g * 22.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[0]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[1]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[2]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[3]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[4]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[5]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[6]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[7]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[8]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[9]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[10]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[11]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[12]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[13]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[14]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[15]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[16]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[17]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[18]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[19]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[20]).g * 3.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[21]).g * 3.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[22]).g * 3.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[23]).g * 3.0; - - sampleColor = sampleColor / 62.0; - - mediump float highPass = centralColor.g - sampleColor + 0.5; - - for(int i = 0; i < 5;i++) - { - highPass = hardLight(highPass); - } - mediump float luminance = dot(centralColor, W); - - mediump float alpha = pow(luminance, params); - - mediump vec3 smoothColor = centralColor + (centralColor-vec3(highPass))*alpha*0.1; - - smoothColor.r = clamp(pow(smoothColor.r, params.g),0.0,1.0); - smoothColor.g = clamp(pow(smoothColor.g, params.g),0.0,1.0); - smoothColor.b = clamp(pow(smoothColor.b, params.g),0.0,1.0); - - mediump vec3 lvse = vec3(1.0)-(vec3(1.0)-smoothColor)*(vec3(1.0)-centralColor); - mediump vec3 bianliang = max(smoothColor, centralColor); - mediump vec3 rouguang = 2.0*centralColor*smoothColor + centralColor*centralColor - 2.0*centralColor*centralColor*smoothColor; - - gl_FragColor = vec4(mix(centralColor, lvse, alpha), 1.0); - gl_FragColor.rgb = mix(gl_FragColor.rgb, bianliang, alpha); - gl_FragColor.rgb = mix(gl_FragColor.rgb, rouguang, params.b); - - mediump vec3 satcolor = gl_FragColor.rgb * saturateMatrix; - gl_FragColor.rgb = mix(gl_FragColor.rgb, satcolor, params.a); - gl_FragColor.rgb = vec3(gl_FragColor.rgb + vec3(brightness)); - } -); + + void main(){ + mediump vec3 centralColor = texture2D(inputImageTexture, textureCoordinate).rgb; + blurCoordinates[0] = textureCoordinate.xy + singleStepOffset * vec2(0.0, -10.0); + blurCoordinates[1] = textureCoordinate.xy + singleStepOffset * vec2(0.0, 10.0); + blurCoordinates[2] = textureCoordinate.xy + singleStepOffset * vec2(-10.0, 0.0); + blurCoordinates[3] = textureCoordinate.xy + singleStepOffset * vec2(10.0, 0.0); + blurCoordinates[4] = textureCoordinate.xy + singleStepOffset * vec2(5.0, -8.0); + blurCoordinates[5] = textureCoordinate.xy + singleStepOffset * vec2(5.0, 8.0); + blurCoordinates[6] = textureCoordinate.xy + singleStepOffset * vec2(-5.0, 8.0); + blurCoordinates[7] = textureCoordinate.xy + singleStepOffset * vec2(-5.0, -8.0); + blurCoordinates[8] = textureCoordinate.xy + singleStepOffset * vec2(8.0, -5.0); + blurCoordinates[9] = textureCoordinate.xy + singleStepOffset * vec2(8.0, 5.0); + blurCoordinates[10] = textureCoordinate.xy + singleStepOffset * vec2(-8.0, 5.0); + blurCoordinates[11] = textureCoordinate.xy + singleStepOffset * vec2(-8.0, -5.0); + blurCoordinates[12] = textureCoordinate.xy + singleStepOffset * vec2(0.0, -6.0); + blurCoordinates[13] = textureCoordinate.xy + singleStepOffset * vec2(0.0, 6.0); + blurCoordinates[14] = textureCoordinate.xy + singleStepOffset * vec2(6.0, 0.0); + blurCoordinates[15] = textureCoordinate.xy + singleStepOffset * vec2(-6.0, 0.0); + blurCoordinates[16] = textureCoordinate.xy + singleStepOffset * vec2(-4.0, -4.0); + blurCoordinates[17] = textureCoordinate.xy + singleStepOffset * vec2(-4.0, 4.0); + blurCoordinates[18] = textureCoordinate.xy + singleStepOffset * vec2(4.0, -4.0); + blurCoordinates[19] = textureCoordinate.xy + singleStepOffset * vec2(4.0, 4.0); + blurCoordinates[20] = textureCoordinate.xy + singleStepOffset * vec2(-2.0, -2.0); + blurCoordinates[21] = textureCoordinate.xy + singleStepOffset * vec2(-2.0, 2.0); + blurCoordinates[22] = textureCoordinate.xy + singleStepOffset * vec2(2.0, -2.0); + blurCoordinates[23] = textureCoordinate.xy + singleStepOffset * vec2(2.0, 2.0); + + mediump float sampleColor = centralColor.g * 22.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[0]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[1]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[2]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[3]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[4]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[5]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[6]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[7]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[8]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[9]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[10]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[11]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[12]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[13]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[14]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[15]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[16]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[17]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[18]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[19]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[20]).g * 3.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[21]).g * 3.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[22]).g * 3.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[23]).g * 3.0; + + sampleColor = sampleColor / 62.0; + + mediump float highPass = centralColor.g - sampleColor + 0.5; + + for (int i = 0; i < 5; i++) { + highPass = hardLight(highPass); + } + mediump float luminance = dot(centralColor, W); + + mediump float alpha = pow(luminance, params); + + mediump vec3 smoothColor = centralColor + (centralColor-vec3(highPass))*alpha*0.1; + + smoothColor.r = clamp(pow(smoothColor.r, params.g), 0.0, 1.0); + smoothColor.g = clamp(pow(smoothColor.g, params.g), 0.0, 1.0); + smoothColor.b = clamp(pow(smoothColor.b, params.g), 0.0, 1.0); + + mediump vec3 lvse = vec3(1.0)-(vec3(1.0)-smoothColor)*(vec3(1.0)-centralColor); + mediump vec3 bianliang = max(smoothColor, centralColor); + mediump vec3 rouguang = 2.0*centralColor*smoothColor + centralColor*centralColor - 2.0*centralColor*centralColor*smoothColor; + + gl_FragColor = vec4(mix(centralColor, lvse, alpha), 1.0); + gl_FragColor.rgb = mix(gl_FragColor.rgb, bianliang, alpha); + gl_FragColor.rgb = mix(gl_FragColor.rgb, rouguang, params.b); + + mediump vec3 satcolor = gl_FragColor.rgb * saturateMatrix; + gl_FragColor.rgb = mix(gl_FragColor.rgb, satcolor, params.a); + gl_FragColor.rgb = vec3(gl_FragColor.rgb + vec3(brightness)); +} + + ); #endif @implementation LFGPUImageBeautyFilter - (id)init; { - if (!(self = [super initWithFragmentShaderFromString:kLFGPUImageBeautyFragmentShaderString])) - { - return nil; + if (!(self = [super initWithFragmentShaderFromString:kLFGPUImageBeautyFragmentShaderString])) { + return nil; } - + _toneLevel = 0.5; _beautyLevel = 0.5; _brightLevel = 0.5; @@ -241,27 +237,23 @@ - (id)init; return self; } -- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex -{ - CGSize oldInputSize = inputTextureSize; +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex { [super setInputSize:newSize atIndex:textureIndex]; inputTextureSize = newSize; - + CGPoint offset = CGPointMake(2.0f / inputTextureSize.width, 2.0 / inputTextureSize.height); [self setPoint:offset forUniformName:@"singleStepOffset"]; } -- (void)setBeautyLevel:(CGFloat)beautyLevel -{ +- (void)setBeautyLevel:(CGFloat)beautyLevel { _beautyLevel = beautyLevel; [self setParams:_beautyLevel tone:_toneLevel]; } -- (void)setBrightLevel:(CGFloat)brightLevel -{ +- (void)setBrightLevel:(CGFloat)brightLevel { _brightLevel = brightLevel; [self setFloat:0.6 * (-0.5 + brightLevel) forUniformName:@"brightness"]; - } +} - (void)setParams:(CGFloat)beauty tone:(CGFloat)tone { GPUVector4 fBeautyParam; diff --git a/LFLiveKit/filter/LFGPUImageEmptyFilter.h b/LFLiveKit/filter/LFGPUImageEmptyFilter.h index fc6ac327..5aad12d6 100755 --- a/LFLiveKit/filter/LFGPUImageEmptyFilter.h +++ b/LFLiveKit/filter/LFGPUImageEmptyFilter.h @@ -1,4 +1,8 @@ -#import "GPUImageFilter.h" +#if __has_include() +#import +#else +#import "GPUImage.h" +#endif @interface LFGPUImageEmptyFilter : GPUImageFilter { diff --git a/LFLiveKit/filter/LFGPUImageEmptyFilter.m b/LFLiveKit/filter/LFGPUImageEmptyFilter.m index e9263d72..9d508cd5 100755 --- a/LFLiveKit/filter/LFGPUImageEmptyFilter.m +++ b/LFLiveKit/filter/LFGPUImageEmptyFilter.m @@ -2,43 +2,42 @@ #if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE NSString *const kLFGPUImageEmptyFragmentShaderString = SHADER_STRING -( - varying highp vec2 textureCoordinate; - - uniform sampler2D inputImageTexture; - - void main() - { + ( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + void main(){ lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); - + gl_FragColor = vec4((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((textureColor.rgb), textureColor.w); - } - ); + ( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + void main(){ + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4((textureColor.rgb), textureColor.w); +} + + ); #endif @implementation LFGPUImageEmptyFilter - (id)init; { - if (!(self = [super initWithFragmentShaderFromString:kLFGPUImageEmptyFragmentShaderString])) - { - return nil; + if (!(self = [super initWithFragmentShaderFromString:kLFGPUImageEmptyFragmentShaderString])) { + return nil; } - + return self; } diff --git a/LFLiveKit/objects/LFAudioFrame.h b/LFLiveKit/objects/LFAudioFrame.h index 8538eb0b..8d355e4a 100755 --- a/LFLiveKit/objects/LFAudioFrame.h +++ b/LFLiveKit/objects/LFAudioFrame.h @@ -2,8 +2,8 @@ // LFAudioFrame.h // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFFrame.h" diff --git a/LFLiveKit/objects/LFAudioFrame.m b/LFLiveKit/objects/LFAudioFrame.m index 4c8c3ed8..03a7c81e 100755 --- a/LFLiveKit/objects/LFAudioFrame.m +++ b/LFLiveKit/objects/LFAudioFrame.m @@ -2,8 +2,8 @@ // LFAudioFrame.m // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFAudioFrame.h" diff --git a/LFLiveKit/objects/LFFrame.h b/LFLiveKit/objects/LFFrame.h index eee870ea..3d1689a9 100755 --- a/LFLiveKit/objects/LFFrame.h +++ b/LFLiveKit/objects/LFFrame.h @@ -2,15 +2,15 @@ // LFFrame.h // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import @interface LFFrame : NSObject -@property (nonatomic, assign) uint64_t timestamp; +@property (nonatomic, assign,) uint64_t timestamp; @property (nonatomic, strong) NSData *data; ///< flv或者rtmp包头 @property (nonatomic, strong) NSData *header; diff --git a/LFLiveKit/objects/LFFrame.m b/LFLiveKit/objects/LFFrame.m index 87f5d98e..434a9a36 100755 --- a/LFLiveKit/objects/LFFrame.m +++ b/LFLiveKit/objects/LFFrame.m @@ -2,8 +2,8 @@ // LFFrame.m // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFFrame.h" diff --git a/LFLiveKit/objects/LFLiveDebug.h b/LFLiveKit/objects/LFLiveDebug.h index 1236e37e..7f4ec844 100644 --- a/LFLiveKit/objects/LFLiveDebug.h +++ b/LFLiveKit/objects/LFLiveDebug.h @@ -2,8 +2,8 @@ // LFLiveDebug.h // LaiFeng // -// Created by admin on 16/5/19. -// Copyright © 2016年 live Interactive. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import @@ -16,11 +16,15 @@ @property (nonatomic, assign) CGSize videoSize; ///< 上传的分辨率 @property (nonatomic, assign) BOOL isRtmp; ///< 上传方式(TCP or RTMP) +@property (nonatomic, assign) CGFloat elapsedMilli; ///< 距离上次统计的时间 单位ms @property (nonatomic, assign) CGFloat timeStamp; ///< 当前的时间戳,从而计算1s内数据 @property (nonatomic, assign) CGFloat dataFlow; ///< 总流量 @property (nonatomic, assign) CGFloat bandwidth; ///< 1s内总带宽 @property (nonatomic, assign) CGFloat currentBandwidth; ///< 上次的带宽 +@property (nonatomic, assign) NSInteger dropFrame; ///< 丢掉的帧数 +@property (nonatomic, assign) NSInteger totalFrame; ///< 总帧数 + @property (nonatomic, assign) NSInteger capturedAudioCount; ///< 1s内音频捕获个数 @property (nonatomic, assign) NSInteger capturedVideoCount; ///< 1s内视频捕获个数 @property (nonatomic, assign) NSInteger currentCapturedAudioCount; ///< 上次的音频捕获个数 diff --git a/LFLiveKit/objects/LFLiveDebug.m b/LFLiveKit/objects/LFLiveDebug.m index 22dc44a0..15210b30 100644 --- a/LFLiveKit/objects/LFLiveDebug.m +++ b/LFLiveKit/objects/LFLiveDebug.m @@ -2,13 +2,17 @@ // LFLiveDebug.m // LaiFeng // -// Created by admin on 16/5/19. -// Copyright © 2016年 live Interactive. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFLiveDebug.h" @implementation LFLiveDebug +- (NSString *)description { + return [NSString stringWithFormat:@"丢掉的帧数:%ld 总帧数:%ld 上次的音频捕获个数:%d 上次的视频捕获个数:%d 未发送个数:%ld 总流量:%0.f",_dropFrame,_totalFrame,_currentCapturedAudioCount,_currentCapturedVideoCount,_unSendCount,_dataFlow]; +} + @end diff --git a/LFLiveKit/objects/LFLiveStreamInfo.h b/LFLiveKit/objects/LFLiveStreamInfo.h index 0b90a006..114e1b09 100755 --- a/LFLiveKit/objects/LFLiveStreamInfo.h +++ b/LFLiveKit/objects/LFLiveStreamInfo.h @@ -2,16 +2,18 @@ // LFLiveStreamInfo.h // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. -// 真正的上传地址 token等 +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. +// #import #import "LFLiveAudioConfiguration.h" #import "LFLiveVideoConfiguration.h" + + /// 流状态 -typedef NS_ENUM(NSUInteger, LFLiveState){ +typedef NS_ENUM (NSUInteger, LFLiveState){ /// 准备 LFLiveReady = 0, /// 连接中 @@ -21,15 +23,17 @@ typedef NS_ENUM(NSUInteger, LFLiveState){ /// 已断开 LFLiveStop = 3, /// 连接出错 - LFLiveError = 4 + LFLiveError = 4, + ///  正在刷新 + LFLiveRefresh = 5 }; -typedef NS_ENUM(NSUInteger,LFLiveSocketErrorCode) { - LFLiveSocketError_PreView = 201,///< 预览失败 - LFLiveSocketError_GetStreamInfo = 202,///< 获取流媒体信息失败 - LFLiveSocketError_ConnectSocket = 203,///< 连接socket失败 - LFLiveSocketError_Verification = 204,///< 验证服务器失败 - LFLiveSocketError_ReConnectTimeOut = 205///< 重新连接服务器超时 +typedef NS_ENUM (NSUInteger, LFLiveSocketErrorCode) { + LFLiveSocketError_PreView = 201, ///< 预览失败 + LFLiveSocketError_GetStreamInfo = 202, ///< 获取流媒体信息失败 + LFLiveSocketError_ConnectSocket = 203, ///< 连接socket失败 + LFLiveSocketError_Verification = 204, ///< 验证服务器失败 + LFLiveSocketError_ReConnectTimeOut = 205 ///< 重新连接服务器超时 }; @interface LFLiveStreamInfo : NSObject @@ -46,5 +50,4 @@ typedef NS_ENUM(NSUInteger,LFLiveSocketErrorCode) { ///视频配置 @property (nonatomic, strong) LFLiveVideoConfiguration *videoConfiguration; - @end diff --git a/LFLiveKit/objects/LFLiveStreamInfo.m b/LFLiveKit/objects/LFLiveStreamInfo.m index 7370aab4..a1a1d971 100755 --- a/LFLiveKit/objects/LFLiveStreamInfo.m +++ b/LFLiveKit/objects/LFLiveStreamInfo.m @@ -2,8 +2,8 @@ // LFLiveStreamInfo.m // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFLiveStreamInfo.h" diff --git a/LFLiveKit/objects/LFVideoFrame.h b/LFLiveKit/objects/LFVideoFrame.h index 78b19875..97e42612 100755 --- a/LFLiveKit/objects/LFVideoFrame.h +++ b/LFLiveKit/objects/LFVideoFrame.h @@ -2,12 +2,13 @@ // LFVideoFrame.h // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFFrame.h" + @interface LFVideoFrame : LFFrame @property (nonatomic, assign) BOOL isKeyFrame; diff --git a/LFLiveKit/objects/LFVideoFrame.m b/LFLiveKit/objects/LFVideoFrame.m index 1dabf13c..b050c38b 100755 --- a/LFLiveKit/objects/LFVideoFrame.m +++ b/LFLiveKit/objects/LFVideoFrame.m @@ -2,8 +2,8 @@ // LFVideoFrame.m // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFVideoFrame.h" diff --git a/LFLiveKit/packet/LFFlvPackage.h b/LFLiveKit/packet/LFFlvPackage.h deleted file mode 100755 index c7a97733..00000000 --- a/LFLiveKit/packet/LFFlvPackage.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// LFFlvPackage.h -// LFLiveKit -// -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. -// - -#import "LFStreamPackage.h" - -@interface LFFlvPackage : NSObject - -#pragma mark - Initializer -///============================================================================= -/// @name Initializer -///============================================================================= -- (nullable instancetype)init UNAVAILABLE_ATTRIBUTE; -+ (nullable instancetype)new UNAVAILABLE_ATTRIBUTE; - -@end diff --git a/LFLiveKit/packet/LFFlvPackage.m b/LFLiveKit/packet/LFFlvPackage.m deleted file mode 100755 index 521871f9..00000000 --- a/LFLiveKit/packet/LFFlvPackage.m +++ /dev/null @@ -1,345 +0,0 @@ -// -// LFFlvPackage.m -// LFLiveKit -// -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. -// - -#import "LFFlvPackage.h" -#include "flv/flv.h" -#include "flv/info.h" - -#define kTagLength (4) -#define kAVCPacketHeaderSize (5) -static const byte kAudioDataHeader = 0xAF; -#define swap_uint32_ htonl - -@interface LFFlvPackage (){ - dispatch_semaphore_t _lock; - NSData *_sps; - NSData *_pps; - NSData *_spec; - CGSize _videoSize; - FILE *fp; - BOOL enabledWriteVideoFile; - BOOL enabledWriteFlvHeaderVideoFile; -} - -@end - -@implementation LFFlvPackage - -- (instancetype)initWithVideoSize:(CGSize)videoSize{ - if(CGSizeEqualToSize(videoSize, CGSizeZero)) @throw [NSException exceptionWithName:@"LFFlvPackage init error" reason:@"video size is zero" userInfo:nil]; - if(self = [super init]){ - _videoSize = videoSize; - _lock = dispatch_semaphore_create(1); -#ifdef DEBUG - enabledWriteVideoFile = NO; - [self initForFilePath]; -#endif - } - return self; -} - -- (void)dealloc{ - -} - -#pragma mark -- LFStreamPackage Delegate -- (NSData*)aaCPacket:(LFAudioFrame*)audioFrame{ - NSMutableData *result = [[NSMutableData alloc] init]; - - dispatch_semaphore_wait(_lock, DISPATCH_TIME_FOREVER); - - if(!_spec){ - _spec = audioFrame.audioInfo; - } - - if(!_sps || !_pps){ - dispatch_semaphore_signal(_lock); - return nil; - } - - // write audio data - uint32 kAACPacketSize = 2; - - NSInteger buffer_size = kAACPacketSize + audioFrame.data.length + FLV_TAG_SIZE; - NSInteger packet_size = buffer_size + kTagLength; - - [result appendData:[[self class] flvTagHeader:FLV_TAG_TYPE_AUDIO size:(int32_t)audioFrame.data.length + kAACPacketSize timeStamp:(uint32)audioFrame.timestamp]]; - - byte format[2] = { kAudioDataHeader, 0x01}; - [result appendBytes:format length:sizeof(format)]; - [result appendData:audioFrame.data]; - - uint32 pre_size = swap_uint32_(packet_size-4); - [result appendBytes:&pre_size length:sizeof(uint32)]; - - audioFrame.header = [[self class] flvHeads:_videoSize.width videoHeight:_videoSize.height sps:_sps pps:_pps audioHeader:_spec]; - if(enabledWriteVideoFile){ - if(!enabledWriteFlvHeaderVideoFile){ - enabledWriteFlvHeaderVideoFile = YES; - fwrite(audioFrame.header.bytes, 1,audioFrame.header.length,self->fp); - } - } - - if(enabledWriteVideoFile) { - fwrite(result.bytes, 1, result.length,self->fp); - } - - dispatch_semaphore_signal(_lock); - return result; -} - -- (NSData*)h264Packet:(LFVideoFrame*)videoFrame{ - NSMutableData *result = [[NSMutableData alloc] init]; - - dispatch_semaphore_wait(_lock, DISPATCH_TIME_FOREVER); - - if(!_sps || !_pps){ - _sps = videoFrame.sps; - _pps = videoFrame.pps; - } - - if(!_spec){ - dispatch_semaphore_signal(_lock); - return nil; - } - - videoFrame.header = [[self class] flvHeads:_videoSize.width videoHeight:_videoSize.height sps:_sps pps:_pps audioHeader:_spec]; - if(enabledWriteVideoFile){ - if(!enabledWriteFlvHeaderVideoFile){ - enabledWriteFlvHeaderVideoFile = YES; - fwrite(videoFrame.header.bytes, 1,videoFrame.header.length,self->fp); - } - } - - // write video data - // Size + buffer size(4 bytes) - uint32 kAVCPacketSize = kAVCPacketHeaderSize + 4; - - size_t buffer_size = kAVCPacketSize + videoFrame.data.length + FLV_TAG_SIZE; - size_t packet_size = buffer_size + kTagLength; - - [result appendData:[[self class] flvTagHeader:FLV_TAG_TYPE_VIDEO size:(int32_t)videoFrame.data.length + kAVCPacketSize timeStamp:(uint32)videoFrame.timestamp]]; - [result appendData:[[self class] h264PacketHeader:videoFrame.isKeyFrame nalu:true]]; - - // write length - size_t size = videoFrame.data.length; - byte length[4] = { 0x00, 0x00, 0x00, 0x00 }; - length[0] = (size >> 24) & 0xff; - length[1] = (size >> 16) & 0xff; - length[2] = (size >> 8) & 0xff; - length[3] = (size >> 0) & 0xff; - [result appendBytes:length length:sizeof(length)]; - - // write tag data - [result appendData:videoFrame.data]; - - uint32 pre_size = swap_uint32_(packet_size-4); - [result appendBytes:&pre_size length:sizeof(uint32)]; - - if(enabledWriteVideoFile) { - fwrite(result.bytes, 1, result.length,self->fp); - } - - dispatch_semaphore_signal(_lock); - return result; -} - -#pragma mark -- FLV -int stream_buffer_write_offset = 0; -static size_t stream_buffer_write(const void * in_buffer, size_t size, void * user_data) { - memcpy(user_data+stream_buffer_write_offset, in_buffer, size); - stream_buffer_write_offset += size; - return size; -} - -+ (NSData*)flvHeader{ - NSMutableData *result = [[NSMutableData alloc] init]; - // 写入 flv header信息 /*<464c5601 05000000 09000000 00>*/ - flv_header header = { }; - uint32_be offset = swap_uint32_(FLV_HEADER_SIZE); - byte extend[kTagLength] = { 0x00, 0x00, 0x00, 0x00 }; - - [result appendBytes:FLV_SIGNATURE length:sizeof(header.signature)]; - uint8 version[] = {FLV_VERSION}; - [result appendBytes:&version length:1]; - uint8 flag[] = {FLV_FLAG_VIDEO | FLV_FLAG_AUDIO}; - [result appendBytes:&flag length:1]; - [result appendBytes:&offset length:sizeof(uint32_be)]; - [result appendBytes:extend length:kTagLength]; - - return result; -} - -+ (NSData*)flvTagHeader:(uint8)type size:(uint32)size timeStamp:(uint32)timeStamp{ - flv_tag tag; - tag.type = type; - tag.body_length = uint32_to_uint24_be(size); - flv_tag_set_timestamp(&tag, timeStamp); - tag.stream_id = uint32_to_uint24_be(0); - - return [NSData dataWithBytes:&tag length:FLV_TAG_SIZE]; -} - -+ (NSData*)h264PacketHeader:(BOOL)keyFrame nalu:(BOOL)nalu{ - byte header[kAVCPacketHeaderSize] = { 0x00, 0x00, 0x00, 0x00, 0x00 }; - header[0] = (keyFrame ? 0x10 : 0x20) | 0x07; - header[1] = nalu ? 0x01 : 0x00; // 1: AVC NALU 0: AVC sequence header - // 后三个字节为Composition time,在AVC中无用 - return [NSData dataWithBytes:header length:sizeof(header)]; -} - -+ (NSData*)metaData:(NSInteger)width height:(NSInteger)height{ - NSMutableData *result = [[NSMutableData alloc] init]; - - flv_metadata meta; - meta.on_metadata_name = amf_str("onMetaData"); - meta.on_metadata = amf_associative_array_new(); - amf_associative_array_add(meta.on_metadata, "width", - amf_number_new(width)); - amf_associative_array_add(meta.on_metadata, "height", - amf_number_new(height)); - amf_associative_array_add(meta.on_metadata, "videocodecid", - amf_number_new((number64)FLV_VIDEO_TAG_CODEC_AVC)); - //usage = base::IntToString(params_.audio_sample_rate); - //amf_associative_array_add(meta.on_metadata, "audiosamplerate", - // amf_str(usage.c_str())); - //usage = base::IntToString(params_.audio_sample_size); - //amf_associative_array_add(meta.on_metadata, "audiosamplesize", - // amf_str(usage.c_str())); - amf_associative_array_add(meta.on_metadata, "stereo", amf_boolean_new(1)); // 对AAC格式: 总为 1 - amf_associative_array_add(meta.on_metadata, "audiocodecid", - amf_number_new((number64)FLV_AUDIO_TAG_SOUND_FORMAT_AAC)); - // create the onMetaData tag - uint32 on_metadata_name_size = (uint32)amf_data_size(meta.on_metadata_name); - uint32 on_metadata_size = (uint32)amf_data_size(meta.on_metadata); - uint32 meta_size = on_metadata_name_size + on_metadata_size; - - size_t buffer_size = meta_size + FLV_TAG_SIZE; - size_t packet_size = true ? buffer_size + kTagLength : buffer_size; - [result appendData:[[self class] flvTagHeader:FLV_TAG_TYPE_META size:meta_size timeStamp:0]]; - - byte metaName[1024] = {0}; - byte metaData[1024] = {0}; - - stream_buffer_write_offset = 0; - size_t metanamelen = amf_data_write(meta.on_metadata_name, stream_buffer_write, metaName); - - stream_buffer_write_offset = 0; - size_t metalen = amf_data_write(meta.on_metadata, stream_buffer_write, metaData); - - amf_data_free(meta.on_metadata_name); - amf_data_free(meta.on_metadata); - - [result appendBytes:metaName length:metanamelen]; - [result appendBytes:metaData length:metalen]; - uint32 pre_size = swap_uint32_(packet_size-4);//为解决第一个pretagsize多了4个而减去4 - [result appendBytes:&pre_size length:sizeof(uint32)]; - - return result; -} - -+ (NSData*)flvTagWithVideoHeader:(NSData*)sps pps:(NSData*)pps{ - NSMutableData *result = [[NSMutableData alloc] init]; - // 封装AVC sequence header - const size_t kExtendSize = 11; - size_t buffer_size = sps.length + pps.length + kExtendSize; - - // AVCPacket header size - size_t body_size = kAVCPacketHeaderSize + buffer_size; - size_t packet_size = body_size + FLV_TAG_SIZE; - // AVCDecoderConfigurationRecord - [result appendData:[[self class] flvTagHeader:FLV_TAG_TYPE_VIDEO size:(UInt32)body_size timeStamp:0]]; - [result appendData:[[self class] h264PacketHeader:YES nalu:NO]]; - - uint8 configuration1[] = {0x01}; - [result appendBytes:&configuration1 length:1]; - [result appendBytes:&sps.bytes[1] length:1]; - [result appendBytes:&sps.bytes[2] length:1]; - [result appendBytes:&sps.bytes[3] length:1]; - uint8 configuration2[] = {0xff}; - [result appendBytes:&configuration2 length:1]; - - // sps - uint8 sps1[] = {0xe1}; - [result appendBytes:&sps1 length:1]; - uint8 sps2[] = {(sps.length >> 8) & 0xff}; - [result appendBytes:&sps2 length:1]; - uint8 sps3[] = {sps.length & 0xff}; - [result appendBytes:&sps3 length:1]; - [result appendBytes:sps.bytes length:sps.length]; - - - // pps - uint8 pps1[] = {0x01}; - [result appendBytes:&pps1 length:1]; - uint8 pps2[] = {(pps.length >> 8) & 0xff}; - [result appendBytes:&pps2 length:1]; - uint8 pps3[] = {pps.length & 0xff}; - [result appendBytes:&pps3 length:1]; - [result appendBytes:pps.bytes length:pps.length]; - - uint32 pre_size = swap_uint32_(packet_size); - [result appendBytes:&pre_size length:sizeof(uint32)]; - - return result; -} - -+ (NSData*)flvTagWithAudioHeader:(NSData*)audioInfo timeStamp:(uint32)timeStamp{ - NSMutableData *result = [[NSMutableData alloc] init]; - const size_t kAACPacketHeaderSize = 2; - - size_t body_size = kAACPacketHeaderSize + audioInfo.length; - size_t packet_size = body_size + FLV_TAG_SIZE; - - [result appendData:[[self class] flvTagHeader:FLV_TAG_TYPE_AUDIO size:(UInt32)body_size timeStamp:timeStamp]]; - - byte format[kAACPacketHeaderSize] = { kAudioDataHeader, 0x01}; - format[1] = 0x00; - [result appendBytes:format length:sizeof(format)]; - [result appendBytes:audioInfo.bytes length:audioInfo.length]; - - uint32 pre_size = swap_uint32_(packet_size); - [result appendBytes:&pre_size length:sizeof(uint32)]; - - return result; -} - -+ (NSData*)flvHeads:(NSInteger)videoWidth videoHeight:(NSInteger)videoHeight sps:(NSData*)sps pps:(NSData*)pps audioHeader:(NSData*)audioHeader{ - NSMutableData *result = [[NSMutableData alloc] init]; - // 写FLV头 - [result appendData:[[self class] flvHeader]]; - // 写 Meta 相关信息 - [result appendData:[[self class] metaData:videoWidth height:videoHeight]]; - // 写音频编码头信息 - [result appendData:[[self class] flvTagWithAudioHeader:audioHeader timeStamp:0]]; - // 写视频编码头信息 - [result appendData:[[self class] flvTagWithVideoHeader:sps pps:pps]]; - - return result; -} - - -#pragma mark -- Debug.. store video to local -- (void)initForFilePath{ - NSString *path = [self GetFilePathByfileName:"flv_publish_x1.flv"]; - [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; - self->fp = fopen([path cStringUsingEncoding:NSUTF8StringEncoding],"wb"); -} - -- (NSString*)GetFilePathByfileName:(char*)filename{ - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask,YES); - NSString *documentsDirectory = [paths objectAtIndex:0]; - NSString *strName = [NSString stringWithFormat:@"%s",filename]; - - NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:strName]; - - - return writablePath; -} - -@end diff --git a/LFLiveKit/packet/LFStreamPackage.h b/LFLiveKit/packet/LFStreamPackage.h deleted file mode 100755 index 26473236..00000000 --- a/LFLiveKit/packet/LFStreamPackage.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// LFStreamPackage.h -// LFLiveKit -// -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. -// - -#import -#import -#import "LFAudioFrame.h" -#import "LFVideoFrame.h" - -/// 编码器抽象的接口 -@protocol LFStreamPackage -@required -- (nullable instancetype)initWithVideoSize:(CGSize)videoSize; -- (nullable NSData*)aaCPacket:(nullable LFAudioFrame*)audioFrame; -- (nullable NSData*)h264Packet:(nullable LFVideoFrame*)videoFrame; -@end - diff --git a/LFLiveKit/packet/flv/amf.c b/LFLiveKit/packet/flv/amf.c deleted file mode 100755 index 7f400ced..00000000 --- a/LFLiveKit/packet/flv/amf.c +++ /dev/null @@ -1,1166 +0,0 @@ -/* - $Id: amf.c 231 2011-06-27 13:46:19Z marc.noirot $ - - FLV Metadata updater - - Copyright (C) 2007-2012 Marc Noirot - - This file is part of FLVMeta. - - FLVMeta is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - FLVMeta 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 General Public License - along with FLVMeta; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#include - -#include "amf.h" - -/* function common to all array types */ -static void amf_list_init(amf_list * list) { - if (list != NULL) { - list->size = 0; - list->first_element = NULL; - list->last_element = NULL; - } -} - -static amf_data * amf_list_push(amf_list * list, amf_data * data) { - amf_node * node = (amf_node*)malloc(sizeof(amf_node)); - if (node != NULL) { - node->data = data; - node->next = NULL; - node->prev = NULL; - if (list->size == 0) { - list->first_element = node; - list->last_element = node; - } - else { - list->last_element->next = node; - node->prev = list->last_element; - list->last_element = node; - } - ++(list->size); - return data; - } - return NULL; -} - -static amf_data * amf_list_insert_before(amf_list * list, amf_node * node, amf_data * data) { - if (node != NULL) { - amf_node * new_node = (amf_node*)malloc(sizeof(amf_node)); - if (new_node != NULL) { - new_node->next = node; - new_node->prev = node->prev; - - if (node->prev != NULL) { - node->prev->next = new_node; - node->prev = new_node; - } - if (node == list->first_element) { - list->first_element = new_node; - } - ++(list->size); - new_node->data = data; - return data; - } - } - return NULL; -} - -static amf_data * amf_list_insert_after(amf_list * list, amf_node * node, amf_data * data) { - if (node != NULL) { - amf_node * new_node = (amf_node*)malloc(sizeof(amf_node)); - if (new_node != NULL) { - new_node->next = node->next; - new_node->prev = node; - - if (node->next != NULL) { - node->next->prev = new_node; - node->next = new_node; - } - if (node == list->last_element) { - list->last_element = new_node; - } - ++(list->size); - new_node->data = data; - return data; - } - } - return NULL; -} - -static amf_data * amf_list_delete(amf_list * list, amf_node * node) { - amf_data * data = NULL; - if (node != NULL) { - if (node->next != NULL) { - node->next->prev = node->prev; - } - if (node->prev != NULL) { - node->prev->next = node->next; - } - if (node == list->first_element) { - list->first_element = node->next; - } - if (node == list->last_element) { - list->last_element = node->prev; - } - data = node->data; - free(node); - --(list->size); - } - return data; -} - -static amf_data * amf_list_get_at(const amf_list * list, uint32 n) { - if (n < list->size) { - uint32 i; - amf_node * node = list->first_element; - for (i = 0; i < n; ++i) { - node = node->next; - } - return node->data; - } - return NULL; -} - -static amf_data * amf_list_pop(amf_list * list) { - return amf_list_delete(list, list->last_element); -} - -static amf_node * amf_list_first(const amf_list * list) { - return list->first_element; -} - -static amf_node * amf_list_last(const amf_list * list) { - return list->last_element; -} - -static void amf_list_clear(amf_list * list) { - amf_node * tmp; - amf_node * node = list->first_element; - while (node != NULL) { - amf_data_free(node->data); - tmp = node; - node = node->next; - free(tmp); - } - list->size = 0; -} - -static amf_list * amf_list_clone(const amf_list * list, amf_list * out_list) { - amf_node * node; - node = list->first_element; - while (node != NULL) { - amf_list_push(out_list, amf_data_clone(node->data)); - node = node->next; - } - return out_list; -} - -/* structure used to mimic a stream with a memory buffer */ -typedef struct __buffer_context { - byte * start_address; - byte * current_address; - size_t buffer_size; -} buffer_context; - -/* callback function to mimic fread using a memory buffer */ -static size_t buffer_read(void * out_buffer, size_t size, void * user_data) { - buffer_context * ctxt = (buffer_context *)user_data; - if (ctxt->current_address >= ctxt->start_address && - ctxt->current_address + size <= ctxt->start_address + ctxt->buffer_size) { - - memcpy(out_buffer, ctxt->current_address, size); - ctxt->current_address += size; - return size; - } - else { - return 0; - } -} - -/* callback function to mimic fwrite using a memory buffer */ -static size_t buffer_write(const void * in_buffer, size_t size, void * user_data) { - buffer_context * ctxt = (buffer_context *)user_data; - if (ctxt->current_address >= ctxt->start_address && - ctxt->current_address + size <= ctxt->start_address + ctxt->buffer_size) { - - memcpy(ctxt->current_address, in_buffer, size); - ctxt->current_address += size; - return size; - } - else { - return 0; - } -} - -/* allocate an AMF data object */ -amf_data * amf_data_new(byte type) { - amf_data * data = (amf_data*)malloc(sizeof(amf_data)); - if (data != NULL) { - data->type = type; - data->error_code = AMF_ERROR_OK; - } - return data; -} - -/* read AMF data from buffer */ -amf_data * amf_data_buffer_read(byte * buffer, size_t maxbytes) { - buffer_context ctxt; - ctxt.start_address = ctxt.current_address = buffer; - ctxt.buffer_size = maxbytes; - return amf_data_read(buffer_read, &ctxt); -} - -/* write AMF data to buffer */ -size_t amf_data_buffer_write(amf_data * data, byte * buffer, size_t maxbytes) { - buffer_context ctxt; - ctxt.start_address = ctxt.current_address = buffer; - ctxt.buffer_size = maxbytes; - return amf_data_write(data, buffer_write, &ctxt); -} - -/* callback function to read data from a file stream */ -static size_t file_read(void * out_buffer, size_t size, void * user_data) { - return fread(out_buffer, sizeof(byte), size, (FILE *)user_data); -} - -/* callback function to write data to a file stream */ -static size_t file_write(const void * in_buffer, size_t size, void * user_data) { - return fwrite(in_buffer, sizeof(byte), size, (FILE *)user_data); -} - -/* load AMF data from a file stream */ -amf_data * amf_data_file_read(FILE * stream) { - return amf_data_read(file_read, stream); -} - -/* write AMF data into a file stream */ -size_t amf_data_file_write(const amf_data * data, FILE * stream) { - return amf_data_write(data, file_write, stream); -} - -/* read a number */ -static amf_data * amf_number_read(amf_read_proc read_proc, void * user_data) { - number64_be val; - if (read_proc(&val, sizeof(number64_be), user_data) == sizeof(number64_be)) { - return amf_number_new(swap_number64(val)); - } - else { - return amf_data_error(AMF_ERROR_EOF); - } -} - -/* read a boolean */ -static amf_data * amf_boolean_read(amf_read_proc read_proc, void * user_data) { - uint8 val; - if (read_proc(&val, sizeof(uint8), user_data) == sizeof(uint8)) { - return amf_boolean_new(val); - } - else { - return amf_data_error(AMF_ERROR_EOF); - } -} - -/* read a string */ -static amf_data * amf_string_read(amf_read_proc read_proc, void * user_data) { - uint16_be strsize; - byte * buffer; - - if (read_proc(&strsize, sizeof(uint16_be), user_data) < sizeof(uint16_be)) { - return amf_data_error(AMF_ERROR_EOF); - } - - strsize = swap_uint16(strsize); - if (strsize == 0) { - return amf_string_new(NULL, 0); - } - - buffer = (byte*)calloc(strsize, sizeof(byte)); - if (buffer == NULL) { - return NULL; - } - - if (read_proc(buffer, strsize, user_data) == strsize) { - amf_data * data = amf_string_new(buffer, strsize); - free(buffer); - return data; - } - else { - free(buffer); - return amf_data_error(AMF_ERROR_EOF); - } -} - -/* read an object */ -static amf_data * amf_object_read(amf_read_proc read_proc, void * user_data) { - amf_data * name; - amf_data * element; - byte error_code; - amf_data * data; - - data = amf_object_new(); - if (data == NULL) { - return NULL; - } - - while (1) { - name = amf_string_read(read_proc, user_data); - error_code = amf_data_get_error_code(name); - if (error_code != AMF_ERROR_OK) { - /* invalid name: error */ - amf_data_free(name); - amf_data_free(data); - return amf_data_error(error_code); - } - - element = amf_data_read(read_proc, user_data); - error_code = amf_data_get_error_code(element); - if (error_code == AMF_ERROR_END_TAG || error_code == AMF_ERROR_UNKNOWN_TYPE) { - /* end tag or unknown element: end of data, exit loop */ - amf_data_free(name); - amf_data_free(element); - break; - } - else if (error_code != AMF_ERROR_OK) { - amf_data_free(name); - amf_data_free(data); - amf_data_free(element); - return amf_data_error(error_code); - } - - if (amf_object_add(data, (char *)amf_string_get_bytes(name), element) == NULL) { - amf_data_free(name); - amf_data_free(element); - amf_data_free(data); - return NULL; - } - else { - amf_data_free(name); - } - } - - return data; -} - -/* read an associative array */ -static amf_data * amf_associative_array_read(amf_read_proc read_proc, void * user_data) { - amf_data * name; - amf_data * element; - uint32_be size; - byte error_code; - amf_data * data; - - data = amf_associative_array_new(); - if (data == NULL) { - return NULL; - } - - /* we ignore the 32 bits array size marker */ - if (read_proc(&size, sizeof(uint32_be), user_data) < sizeof(uint32_be)) { - amf_data_free(data); - return amf_data_error(AMF_ERROR_EOF); - } - - while(1) { - name = amf_string_read(read_proc, user_data); - error_code = amf_data_get_error_code(name); - if (error_code != AMF_ERROR_OK) { - /* invalid name: error */ - amf_data_free(name); - amf_data_free(data); - return amf_data_error(error_code); - } - - element = amf_data_read(read_proc, user_data); - error_code = amf_data_get_error_code(element); - - if (amf_string_get_size(name) == 0 || error_code == AMF_ERROR_END_TAG || error_code == AMF_ERROR_UNKNOWN_TYPE) { - /* end tag or unknown element: end of data, exit loop */ - amf_data_free(name); - amf_data_free(element); - break; - } - else if (error_code != AMF_ERROR_OK) { - amf_data_free(name); - amf_data_free(data); - amf_data_free(element); - return amf_data_error(error_code); - } - - if (amf_associative_array_add(data, (char *)amf_string_get_bytes(name), element) == NULL) { - amf_data_free(name); - amf_data_free(element); - amf_data_free(data); - return NULL; - } - else { - amf_data_free(name); - } - } - - return data; -} - -/* read an array */ -static amf_data * amf_array_read(amf_read_proc read_proc, void * user_data) { - size_t i; - amf_data * element; - byte error_code; - amf_data * data; - uint32 array_size; - - data = amf_array_new(); - if (data == NULL) { - return NULL; - } - - if (read_proc(&array_size, sizeof(uint32), user_data) < sizeof(uint32)) { - amf_data_free(data); - return amf_data_error(AMF_ERROR_EOF); - } - - array_size = swap_uint32(array_size); - - for (i = 0; i < array_size; ++i) { - element = amf_data_read(read_proc, user_data); - error_code = amf_data_get_error_code(element); - if (error_code != AMF_ERROR_OK) { - amf_data_free(element); - amf_data_free(data); - return amf_data_error(error_code); - } - - if (amf_array_push(data, element) == NULL) { - amf_data_free(element); - amf_data_free(data); - return NULL; - } - } - - return data; -} - -/* read a date */ -static amf_data * amf_date_read(amf_read_proc read_proc, void * user_data) { - number64_be milliseconds; - sint16_be timezone; - if (read_proc(&milliseconds, sizeof(number64_be), user_data) == sizeof(number64_be) && - read_proc(&timezone, sizeof(sint16_be), user_data) == sizeof(sint16_be)) { - return amf_date_new(swap_number64(milliseconds), swap_sint16(timezone)); - } - else { - return amf_data_error(AMF_ERROR_EOF); - } -} - -/* load AMF data from stream */ -amf_data * amf_data_read(amf_read_proc read_proc, void * user_data) { - byte type; - if (read_proc(&type, sizeof(byte), user_data) < sizeof(byte)) { - return amf_data_error(AMF_ERROR_EOF); - } - - switch (type) { - case AMF_TYPE_NUMBER: - return amf_number_read(read_proc, user_data); - case AMF_TYPE_BOOLEAN: - return amf_boolean_read(read_proc, user_data); - case AMF_TYPE_STRING: - return amf_string_read(read_proc, user_data); - case AMF_TYPE_OBJECT: - return amf_object_read(read_proc, user_data); - case AMF_TYPE_NULL: - return amf_null_new(); - case AMF_TYPE_UNDEFINED: - return amf_undefined_new(); - /*case AMF_TYPE_REFERENCE:*/ - case AMF_TYPE_ASSOCIATIVE_ARRAY: - return amf_associative_array_read(read_proc, user_data); - case AMF_TYPE_ARRAY: - return amf_array_read(read_proc, user_data); - case AMF_TYPE_DATE: - return amf_date_read(read_proc, user_data); - /*case AMF_TYPE_SIMPLEOBJECT:*/ - case AMF_TYPE_XML: - case AMF_TYPE_CLASS: - return amf_data_error(AMF_ERROR_UNSUPPORTED_TYPE); - case AMF_TYPE_END: - return amf_data_error(AMF_ERROR_END_TAG); /* end of composite object */ - default: - return amf_data_error(AMF_ERROR_UNKNOWN_TYPE); - } -} - -/* determines the size of the given AMF data */ -size_t amf_data_size(const amf_data * data) { - size_t s = 0; - amf_node * node; - if (data != NULL) { - s += sizeof(byte); - switch (data->type) { - case AMF_TYPE_NUMBER: - s += sizeof(number64_be); - break; - case AMF_TYPE_BOOLEAN: - s += sizeof(uint8); - break; - case AMF_TYPE_STRING: - s += sizeof(uint16) + (size_t)amf_string_get_size(data); - break; - case AMF_TYPE_OBJECT: - node = amf_object_first(data); - while (node != NULL) { - s += sizeof(uint16) + (size_t)amf_string_get_size(amf_object_get_name(node)); - s += (size_t)amf_data_size(amf_object_get_data(node)); - node = amf_object_next(node); - } - s += sizeof(uint16) + sizeof(uint8); - break; - case AMF_TYPE_NULL: - case AMF_TYPE_UNDEFINED: - break; - /*case AMF_TYPE_REFERENCE:*/ - case AMF_TYPE_ASSOCIATIVE_ARRAY: - s += sizeof(uint32); - node = amf_associative_array_first(data); - while (node != NULL) { - s += sizeof(uint16) + (size_t)amf_string_get_size(amf_associative_array_get_name(node)); - s += (size_t)amf_data_size(amf_associative_array_get_data(node)); - node = amf_associative_array_next(node); - } - s += sizeof(uint16) + sizeof(uint8); - break; - case AMF_TYPE_ARRAY: - s += sizeof(uint32); - node = amf_array_first(data); - while (node != NULL) { - s += (size_t)amf_data_size(amf_array_get(node)); - node = amf_array_next(node); - } - break; - case AMF_TYPE_DATE: - s += sizeof(number64) + sizeof(sint16); - break; - /*case AMF_TYPE_SIMPLEOBJECT:*/ - case AMF_TYPE_XML: - case AMF_TYPE_CLASS: - case AMF_TYPE_END: - break; /* end of composite object */ - default: - break; - } - } - return s; -} - -/* write a number */ -static size_t amf_number_write(const amf_data * data, amf_write_proc write_proc, void * user_data) { - number64 n = swap_number64(data->number_data); - return write_proc(&n, sizeof(number64_be), user_data); -} - -/* write a boolean */ -static size_t amf_boolean_write(const amf_data * data, amf_write_proc write_proc, void * user_data) { - return write_proc(&(data->boolean_data), sizeof(uint8), user_data); -} - -/* write a string */ -static size_t amf_string_write(const amf_data * data, amf_write_proc write_proc, void * user_data) { - uint16 s; - size_t w = 0; - - s = swap_uint16(data->string_data.size); - w = write_proc(&s, sizeof(uint16_be), user_data); - if (data->string_data.size > 0) { - w += write_proc(data->string_data.mbstr, (size_t)(data->string_data.size), user_data); - } - - return w; -} - -/* write an object */ -static size_t amf_object_write(const amf_data * data, amf_write_proc write_proc, void * user_data) { - amf_node * node; - size_t w = 0; - uint16_be filler = swap_uint16(0); - uint8 terminator = AMF_TYPE_END; - - node = amf_object_first(data); - while (node != NULL) { - w += amf_string_write(amf_object_get_name(node), write_proc, user_data); - w += amf_data_write(amf_object_get_data(node), write_proc, user_data); - node = amf_object_next(node); - } - - /* empty string is the last element */ - w += write_proc(&filler, sizeof(uint16_be), user_data); - /* an object ends with 0x09 */ - w += write_proc(&terminator, sizeof(uint8), user_data); - - return w; -} - -/* write an associative array */ -static size_t amf_associative_array_write(const amf_data * data, amf_write_proc write_proc, void * user_data) { - amf_node * node; - size_t w = 0; - uint32_be s; - uint16_be filler = swap_uint16(0); - uint8 terminator = AMF_TYPE_END; - - s = swap_uint32(data->list_data.size) / 2; - w += write_proc(&s, sizeof(uint32_be), user_data); - node = amf_associative_array_first(data); - while (node != NULL) { - w += amf_string_write(amf_associative_array_get_name(node), write_proc, user_data); - w += amf_data_write(amf_associative_array_get_data(node), write_proc, user_data); - node = amf_associative_array_next(node); - } - - /* empty string is the last element */ - w += write_proc(&filler, sizeof(uint16_be), user_data); - /* an object ends with 0x09 */ - w += write_proc(&terminator, sizeof(uint8), user_data); - - return w; -} - -/* write an array */ -static size_t amf_array_write(const amf_data * data, amf_write_proc write_proc, void * user_data) { - amf_node * node; - size_t w = 0; - uint32_be s; - - s = swap_uint32(data->list_data.size); - w += write_proc(&s, sizeof(uint32_be), user_data); - node = amf_array_first(data); - while (node != NULL) { - w += amf_data_write(amf_array_get(node), write_proc, user_data); - node = amf_array_next(node); - } - - return w; -} - -/* write a date */ -static size_t amf_date_write(const amf_data * data, amf_write_proc write_proc, void * user_data) { - size_t w = 0; - number64_be milli; - sint16_be tz; - - milli = swap_number64(data->date_data.milliseconds); - w += write_proc(&milli, sizeof(number64_be), user_data); - tz = swap_sint16(data->date_data.timezone); - w += write_proc(&tz, sizeof(sint16_be), user_data); - - return w; -} - -/* write amf data to stream */ -size_t amf_data_write(const amf_data * data, amf_write_proc write_proc, void * user_data) { - size_t s = 0; - if (data != NULL) { - s += write_proc(&(data->type), sizeof(byte), user_data); - switch (data->type) { - case AMF_TYPE_NUMBER: - s += amf_number_write(data, write_proc, user_data); - break; - case AMF_TYPE_BOOLEAN: - s += amf_boolean_write(data, write_proc, user_data); - break; - case AMF_TYPE_STRING: - s += amf_string_write(data, write_proc, user_data); - break; - case AMF_TYPE_OBJECT: - s += amf_object_write(data, write_proc, user_data); - break; - case AMF_TYPE_NULL: - case AMF_TYPE_UNDEFINED: - break; - /*case AMF_TYPE_REFERENCE:*/ - case AMF_TYPE_ASSOCIATIVE_ARRAY: - s += amf_associative_array_write(data, write_proc, user_data); - break; - case AMF_TYPE_ARRAY: - s += amf_array_write(data, write_proc, user_data); - break; - case AMF_TYPE_DATE: - s += amf_date_write(data, write_proc, user_data); - break; - /*case AMF_TYPE_SIMPLEOBJECT:*/ - case AMF_TYPE_XML: - case AMF_TYPE_CLASS: - case AMF_TYPE_END: - break; /* end of composite object */ - default: - break; - } - } - return s; -} - -/* data type */ -byte amf_data_get_type(const amf_data * data) { - return (data != NULL) ? data->type : AMF_TYPE_NULL; -} - -/* error code */ -byte amf_data_get_error_code(const amf_data * data) { - return (data != NULL) ? data->error_code : AMF_ERROR_NULL_POINTER; -} - -/* clone AMF data */ -amf_data * amf_data_clone(const amf_data * data) { - /* we copy data recursively */ - if (data != NULL) { - switch (data->type) { - case AMF_TYPE_NUMBER: return amf_number_new(amf_number_get_value(data)); - case AMF_TYPE_BOOLEAN: return amf_boolean_new(amf_boolean_get_value(data)); - case AMF_TYPE_STRING: - if (data->string_data.mbstr != NULL) { - return amf_string_new((byte *)strdup((char *)amf_string_get_bytes(data)), amf_string_get_size(data)); - } - else { - return amf_str(NULL); - } - case AMF_TYPE_NULL: return NULL; - case AMF_TYPE_UNDEFINED: return NULL; - /*case AMF_TYPE_REFERENCE:*/ - case AMF_TYPE_OBJECT: - case AMF_TYPE_ASSOCIATIVE_ARRAY: - case AMF_TYPE_ARRAY: - { - amf_data * d = amf_data_new(data->type); - if (d != NULL) { - amf_list_init(&d->list_data); - amf_list_clone(&data->list_data, &d->list_data); - } - return d; - } - case AMF_TYPE_DATE: return amf_date_new(amf_date_get_milliseconds(data), amf_date_get_timezone(data)); - /*case AMF_TYPE_SIMPLEOBJECT:*/ - case AMF_TYPE_XML: return NULL; - case AMF_TYPE_CLASS: return NULL; - } - } - return NULL; -} - -/* free AMF data */ -void amf_data_free(amf_data * data) { - if (data != NULL) { - switch (data->type) { - case AMF_TYPE_NUMBER: break; - case AMF_TYPE_BOOLEAN: break; - case AMF_TYPE_STRING: - if (data->string_data.mbstr != NULL) { - free(data->string_data.mbstr); - } break; - case AMF_TYPE_NULL: break; - case AMF_TYPE_UNDEFINED: break; - /*case AMF_TYPE_REFERENCE:*/ - case AMF_TYPE_OBJECT: - case AMF_TYPE_ASSOCIATIVE_ARRAY: - case AMF_TYPE_ARRAY: amf_list_clear(&data->list_data); break; - case AMF_TYPE_DATE: break; - /*case AMF_TYPE_SIMPLEOBJECT:*/ - case AMF_TYPE_XML: break; - case AMF_TYPE_CLASS: break; - default: break; - } - free(data); - } -} - -/* dump AMF data into a stream as text */ -void amf_data_dump(FILE * stream, const amf_data * data, int indent_level) { - if (data != NULL) { - amf_node * node; - time_t time; - struct tm * t = NULL; - char datestr[128]; - switch (data->type) { - case AMF_TYPE_NUMBER: - fprintf(stream, "%.12g", data->number_data); - break; - case AMF_TYPE_BOOLEAN: - fprintf(stream, "%s", (data->boolean_data) ? "true" : "false"); - break; - case AMF_TYPE_STRING: - fprintf(stream, "\'%.*s\'", data->string_data.size, data->string_data.mbstr); - break; - case AMF_TYPE_OBJECT: - node = amf_object_first(data); - fprintf(stream, "{\n"); - while (node != NULL) { - fprintf(stream, "%*s", (indent_level+1)*4, ""); - amf_data_dump(stream, amf_object_get_name(node), indent_level+1); - fprintf(stream, ": "); - amf_data_dump(stream, amf_object_get_data(node), indent_level+1); - node = amf_object_next(node); - fprintf(stream, "\n"); - } - fprintf(stream, "%*s", indent_level*4 + 1, "}"); - break; - case AMF_TYPE_NULL: - fprintf(stream, "null"); - break; - case AMF_TYPE_UNDEFINED: - fprintf(stream, "undefined"); - break; - /*case AMF_TYPE_REFERENCE:*/ - case AMF_TYPE_ASSOCIATIVE_ARRAY: - node = amf_associative_array_first(data); - fprintf(stream, "{\n"); - while (node != NULL) { - fprintf(stream, "%*s", (indent_level+1)*4, ""); - amf_data_dump(stream, amf_associative_array_get_name(node), indent_level+1); - fprintf(stream, " => "); - amf_data_dump(stream, amf_associative_array_get_data(node), indent_level+1); - node = amf_associative_array_next(node); - fprintf(stream, "\n"); - } - fprintf(stream, "%*s", indent_level*4 + 1, "}"); - break; - case AMF_TYPE_ARRAY: - node = amf_array_first(data); - fprintf(stream, "[\n"); - while (node != NULL) { - fprintf(stream, "%*s", (indent_level+1)*4, ""); - amf_data_dump(stream, node->data, indent_level+1); - node = amf_array_next(node); - fprintf(stream, "\n"); - } - fprintf(stream, "%*s", indent_level*4 + 1, "]"); - break; - case AMF_TYPE_DATE: - time = amf_date_to_time_t(data); - tzset(); - localtime_r(&time,t); - strftime(datestr, sizeof(datestr), "%a, %d %b %Y %H:%M:%S %z", t); - fprintf(stream, "%s", datestr); - break; - /*case AMF_TYPE_SIMPLEOBJECT:*/ - case AMF_TYPE_XML: break; - case AMF_TYPE_CLASS: break; - default: break; - } - } -} - -/* return a null AMF object with the specified error code attached to it */ -amf_data * amf_data_error(byte error_code) { - amf_data * data = amf_null_new(); - if (data != NULL) { - data->error_code = error_code; - } - return data; -} - -/* number functions */ -amf_data * amf_number_new(number64 value) { - amf_data * data = amf_data_new(AMF_TYPE_NUMBER); - if (data != NULL) { - data->number_data = value; - } - return data; -} - -amf_data * amf_number_double(double value) { - amf_data * data = amf_data_new(AMF_TYPE_NUMBER); - if (data != NULL) { - data->number_data = value; - } - return data; -} - -number64 amf_number_get_value(const amf_data * data) { - return (data != NULL) ? data->number_data : 0; -} - -void amf_number_set_value(amf_data * data, number64 value) { - if (data != NULL) { - data->number_data = value; - } -} - -/* boolean functions */ -amf_data * amf_boolean_new(uint8 value) { - amf_data * data = amf_data_new(AMF_TYPE_BOOLEAN); - if (data != NULL) { - data->boolean_data = value; - } - return data; -} - -uint8 amf_boolean_get_value(const amf_data * data) { - return (data != NULL) ? data->boolean_data : 0; -} - -void amf_boolean_set_value(amf_data * data, uint8 value) { - if (data != NULL) { - data->boolean_data = value; - } -} - -/* string functions */ -amf_data * amf_string_new(byte * str, uint16 size) { - amf_data * data = amf_data_new(AMF_TYPE_STRING); - if (data != NULL) { - if (str == NULL) { - data->string_data.size = 0; - } - else { - data->string_data.size = size; - } - data->string_data.mbstr = (byte*)calloc(size+1, sizeof(byte)); - if (data->string_data.mbstr != NULL) { - if (data->string_data.size > 0) { - memcpy(data->string_data.mbstr, str, data->string_data.size); - } - } - else { - amf_data_free(data); - return NULL; - } - } - return data; -} - -amf_data * amf_str(const char * str) { - return amf_string_new((byte *)str, (uint16)(str != NULL ? strlen(str) : 0)); -} - -uint16 amf_string_get_size(const amf_data * data) { - return (data != NULL) ? data->string_data.size : 0; -} - -byte * amf_string_get_bytes(const amf_data * data) { - return (data != NULL) ? data->string_data.mbstr : NULL; -} - -/* object functions */ -amf_data * amf_object_new(void) { - amf_data * data = amf_data_new(AMF_TYPE_OBJECT); - if (data != NULL) { - amf_list_init(&data->list_data); - } - return data; -} - -uint32 amf_object_size(const amf_data * data) { - return (data != NULL) ? data->list_data.size / 2 : 0; -} - -amf_data * amf_object_add(amf_data * data, const char * name, amf_data * element) { - if (data != NULL) { - if (amf_list_push(&data->list_data, amf_str(name)) != NULL) { - if (amf_list_push(&data->list_data, element) != NULL) { - return element; - } - else { - amf_data_free(amf_list_pop(&data->list_data)); - } - } - } - return NULL; -} - -amf_data * amf_object_get(const amf_data * data, const char * name) { - if (data != NULL) { - amf_node * node = amf_list_first(&(data->list_data)); - while (node != NULL) { - if (strncmp((char*)(node->data->string_data.mbstr), name, (size_t)(node->data->string_data.size)) == 0) { - node = node->next; - return (node != NULL) ? node->data : NULL; - } - /* we have to skip the element data to reach the next name */ - node = node->next->next; - } - } - return NULL; -} - -amf_data * amf_object_set(amf_data * data, const char * name, amf_data * element) { - if (data != NULL) { - amf_node * node = amf_list_first(&(data->list_data)); - while (node != NULL) { - if (strncmp((char*)(node->data->string_data.mbstr), name, (size_t)(node->data->string_data.size)) == 0) { - node = node->next; - if (node != NULL && node->data != NULL) { - amf_data_free(node->data); - node->data = element; - return element; - } - } - /* we have to skip the element data to reach the next name */ - node = node->next->next; - } - } - return NULL; -} - -amf_data * amf_object_delete(amf_data * data, const char * name) { - if (data != NULL) { - amf_node * node = amf_list_first(&data->list_data); - while (node != NULL) { - node = node->next; - if (strncmp((char*)(node->data->string_data.mbstr), name, (size_t)(node->data->string_data.size)) == 0) { - amf_node * data_node = node->next; - amf_data_free(amf_list_delete(&data->list_data, node)); - return amf_list_delete(&data->list_data, data_node); - } - else { - node = node->next; - } - } - } - return NULL; -} - -amf_node * amf_object_first(const amf_data * data) { - return (data != NULL) ? amf_list_first(&data->list_data) : NULL; -} - -amf_node * amf_object_last(const amf_data * data) { - if (data != NULL) { - amf_node * node = amf_list_last(&data->list_data); - if (node != NULL) { - return node->prev; - } - } - return NULL; -} - -amf_node * amf_object_next(amf_node * node) { - if (node != NULL) { - amf_node * next = node->next; - if (next != NULL) { - return next->next; - } - } - return NULL; -} - -amf_node * amf_object_prev(amf_node * node) { - if (node != NULL) { - amf_node * prev = node->prev; - if (prev != NULL) { - return prev->prev; - } - } - return NULL; -} - -amf_data * amf_object_get_name(amf_node * node) { - return (node != NULL) ? node->data : NULL; -} - -amf_data * amf_object_get_data(amf_node * node) { - if (node != NULL) { - amf_node * next = node->next; - if (next != NULL) { - return next->data; - } - } - return NULL; -} - -/* associative array functions */ -amf_data * amf_associative_array_new(void) { - amf_data * data = amf_data_new(AMF_TYPE_ASSOCIATIVE_ARRAY); - if (data != NULL) { - amf_list_init(&data->list_data); - } - return data; -} - -/* array functions */ -amf_data * amf_array_new(void) { - amf_data * data = amf_data_new(AMF_TYPE_ARRAY); - if (data != NULL) { - amf_list_init(&data->list_data); - } - return data; -} - -uint32 amf_array_size(const amf_data * data) { - return (data != NULL) ? data->list_data.size : 0; -} - -amf_data * amf_array_push(amf_data * data, amf_data * element) { - return (data != NULL) ? amf_list_push(&data->list_data, element) : NULL; -} - -amf_data * amf_array_pop(amf_data * data) { - return (data != NULL) ? amf_list_pop(&data->list_data) : NULL; -} - -amf_node * amf_array_first(const amf_data * data) { - return (data != NULL) ? amf_list_first(&data->list_data) : NULL; -} - -amf_node * amf_array_last(const amf_data * data) { - return (data != NULL) ? amf_list_last(&data->list_data) : NULL; -} - -amf_node * amf_array_next(amf_node * node) { - return (node != NULL) ? node->next : NULL; -} - -amf_node * amf_array_prev(amf_node * node) { - return (node != NULL) ? node->prev : NULL; -} - -amf_data * amf_array_get(amf_node * node) { - return (node != NULL) ? node->data : NULL; -} - -amf_data * amf_array_get_at(const amf_data * data, uint32 n) { - return (data != NULL) ? amf_list_get_at(&data->list_data, n) : NULL; -} - -amf_data * amf_array_delete(amf_data * data, amf_node * node) { - return (data != NULL) ? amf_list_delete(&data->list_data, node) : NULL; -} - -amf_data * amf_array_insert_before(amf_data * data, amf_node * node, amf_data * element) { - return (data != NULL) ? amf_list_insert_before(&data->list_data, node, element) : NULL; -} - -amf_data * amf_array_insert_after(amf_data * data, amf_node * node, amf_data * element) { - return (data != NULL) ? amf_list_insert_after(&data->list_data, node, element) : NULL; -} - -/* date functions */ -amf_data * amf_date_new(number64 milliseconds, sint16 timezone) { - amf_data * data = amf_data_new(AMF_TYPE_DATE); - if (data != NULL) { - data->date_data.milliseconds = milliseconds; - data->date_data.timezone = timezone; - } - return data; -} - -number64 amf_date_get_milliseconds(const amf_data * data) { - return (data != NULL) ? data->date_data.milliseconds : (number64)0.0; -} - -sint16 amf_date_get_timezone(const amf_data * data) { - return (data != NULL) ? data->date_data.timezone : 0; -} - -time_t amf_date_to_time_t(const amf_data * data) { - return (time_t)((data != NULL) ? data->date_data.milliseconds / 1000 : 0); -} diff --git a/LFLiveKit/packet/flv/amf.h b/LFLiveKit/packet/flv/amf.h deleted file mode 100755 index cf045d2f..00000000 --- a/LFLiveKit/packet/flv/amf.h +++ /dev/null @@ -1,231 +0,0 @@ -/* - $Id: amf.h 231 2011-06-27 13:46:19Z marc.noirot $ - - FLV Metadata updater - - Copyright (C) 2007-2012 Marc Noirot - - This file is part of FLVMeta. - - FLVMeta is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - FLVMeta 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 General Public License - along with FLVMeta; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#ifndef __AMF_H__ -#define __AMF_H__ - -#include -#include -#include - -#include "types.h" - -/* AMF data types */ -#define AMF_TYPE_NUMBER ((byte)0x00) -#define AMF_TYPE_BOOLEAN ((byte)0x01) -#define AMF_TYPE_STRING ((byte)0x02) -#define AMF_TYPE_OBJECT ((byte)0x03) -#define AMF_TYPE_NULL ((byte)0x05) -#define AMF_TYPE_UNDEFINED ((byte)0x06) -/* #define AMF_TYPE_REFERENCE ((byte)0x07) */ -#define AMF_TYPE_ASSOCIATIVE_ARRAY ((byte)0x08) -#define AMF_TYPE_END ((byte)0x09) -#define AMF_TYPE_ARRAY ((byte)0x0A) -#define AMF_TYPE_DATE ((byte)0x0B) -/* #define AMF_TYPE_SIMPLEOBJECT ((byte)0x0D) */ -#define AMF_TYPE_XML ((byte)0x0F) -#define AMF_TYPE_CLASS ((byte)0x10) - -/* AMF error codes */ -#define AMF_ERROR_OK ((byte)0x00) -#define AMF_ERROR_EOF ((byte)0x01) -#define AMF_ERROR_UNKNOWN_TYPE ((byte)0x02) -#define AMF_ERROR_END_TAG ((byte)0x03) -#define AMF_ERROR_NULL_POINTER ((byte)0x04) -#define AMF_ERROR_MEMORY ((byte)0x05) -#define AMF_ERROR_UNSUPPORTED_TYPE ((byte)0x06) - -typedef struct __amf_node * p_amf_node; - -/* string type */ -typedef struct __amf_string { - uint16 size; - byte * mbstr; -} amf_string; - -/* array type */ -typedef struct __amf_list { - uint32 size; - p_amf_node first_element; - p_amf_node last_element; -} amf_list; - -/* date type */ -typedef struct __amf_date { - number64 milliseconds; - sint16 timezone; -} amf_date; - -/* XML string type */ -typedef struct __amf_xmlstring { - uint32 size; - byte * mbstr; -} amf_xmlstring; - -/* class type */ -typedef struct __amf_class { - amf_string name; - amf_list elements; -} amf_class; - -/* structure encapsulating the various AMF objects */ -typedef struct __amf_data { - byte type; - byte error_code; - union { - number64 number_data; - uint8 boolean_data; - amf_string string_data; - amf_list list_data; - amf_date date_data; - amf_xmlstring xmlstring_data; - amf_class class_data; - }; -} amf_data; - -/* node used in lists, relies on amf_data */ -typedef struct __amf_node { - amf_data * data; - p_amf_node prev; - p_amf_node next; -} amf_node; - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* Pluggable backend support */ -typedef size_t (*amf_read_proc)(void * out_buffer, size_t size, void * user_data); -typedef size_t (*amf_write_proc)(const void * in_buffer, size_t size, void * user_data); - -/* read AMF data */ -amf_data * amf_data_read(amf_read_proc read_proc, void * user_data); - -/* write AMF data */ -size_t amf_data_write(const amf_data * data, amf_write_proc write_proc, void * user_data); - -/* generic functions */ - -/* allocate an AMF data object */ -amf_data * amf_data_new(byte type); -/* load AMF data from buffer */ -amf_data * amf_data_buffer_read(byte * buffer, size_t maxbytes); -/* load AMF data from stream */ -amf_data * amf_data_file_read(FILE * stream); -/* AMF data size */ -size_t amf_data_size(const amf_data * data); -/* write encoded AMF data into a buffer */ -size_t amf_data_buffer_write(amf_data * data, byte * buffer, size_t maxbytes); -/* write encoded AMF data into a stream */ -size_t amf_data_file_write(const amf_data * data, FILE * stream); -/* get the type of AMF data */ -byte amf_data_get_type(const amf_data * data); -/* get the error code of AMF data */ -byte amf_data_get_error_code(const amf_data * data); -/* return a new copy of AMF data */ -amf_data * amf_data_clone(const amf_data * data); -/* release the memory of AMF data */ -void amf_data_free(amf_data * data); -/* dump AMF data into a stream as text */ -void amf_data_dump(FILE * stream, const amf_data * data, int indent_level); - -/* return a null AMF object with the specified error code attached to it */ -amf_data * amf_data_error(byte error_code); - -/* number functions */ -amf_data * amf_number_new(number64 value); -amf_data * amf_number_double(double value); -number64 amf_number_get_value(const amf_data * data); -void amf_number_set_value(amf_data * data, number64 value); - -/* boolean functions */ -amf_data * amf_boolean_new(uint8 value); -uint8 amf_boolean_get_value(const amf_data * data); -void amf_boolean_set_value(amf_data * data, uint8 value); - -/* string functions */ -amf_data * amf_string_new(byte * str, uint16 size); -amf_data * amf_str(const char * str); -uint16 amf_string_get_size(const amf_data * data); -byte * amf_string_get_bytes(const amf_data * data); - -/* object functions */ -amf_data * amf_object_new(void); -uint32 amf_object_size(const amf_data * data); -amf_data * amf_object_add(amf_data * data, const char * name, amf_data * element); -amf_data * amf_object_get(const amf_data * data, const char * name); -amf_data * amf_object_set(amf_data * data, const char * name, amf_data * element); -amf_data * amf_object_delete(amf_data * data, const char * name); -amf_node * amf_object_first(const amf_data * data); -amf_node * amf_object_last(const amf_data * data); -amf_node * amf_object_next(amf_node * node); -amf_node * amf_object_prev(amf_node * node); -amf_data * amf_object_get_name(amf_node * node); -amf_data * amf_object_get_data(amf_node * node); - -/* null functions */ -#define amf_null_new() amf_data_new(AMF_TYPE_NULL) - -/* undefined functions */ -#define amf_undefined_new() amf_data_new(AMF_TYPE_UNDEFINED) - -/* associative array functions */ -amf_data * amf_associative_array_new(void); -#define amf_associative_array_size(d) amf_object_size(d) -#define amf_associative_array_add(d, n, e) amf_object_add(d, n, e) -#define amf_associative_array_get(d, n) amf_object_get(d, n) -#define amf_associative_array_set(d, n, e) amf_object_set(d, n, e) -#define amf_associative_array_delete(d, n) amf_object_delete(d, n) -#define amf_associative_array_first(d) amf_object_first(d) -#define amf_associative_array_last(d) amf_object_last(d) -#define amf_associative_array_next(n) amf_object_next(n) -#define amf_associative_array_prev(n) amf_object_prev(n) -#define amf_associative_array_get_name(n) amf_object_get_name(n) -#define amf_associative_array_get_data(n) amf_object_get_data(n) - -/* array functions */ -amf_data * amf_array_new(void); -uint32 amf_array_size(const amf_data * data); -amf_data * amf_array_push(amf_data * data, amf_data * element); -amf_data * amf_array_pop(amf_data * data); -amf_node * amf_array_first(const amf_data * data); -amf_node * amf_array_last(const amf_data * data); -amf_node * amf_array_next(amf_node * node); -amf_node * amf_array_prev(amf_node * node); -amf_data * amf_array_get(amf_node * node); -amf_data * amf_array_get_at(const amf_data * data, uint32 n); -amf_data * amf_array_delete(amf_data * data, amf_node * node); -amf_data * amf_array_insert_before(amf_data * data, amf_node * node, amf_data * element); -amf_data * amf_array_insert_after(amf_data * data, amf_node * node, amf_data * element); - -/* date functions */ -amf_data * amf_date_new(number64 milliseconds, sint16 timezone); -number64 amf_date_get_milliseconds(const amf_data * data); -sint16 amf_date_get_timezone(const amf_data * data); -time_t amf_date_to_time_t(const amf_data * data); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __AMF_H__ */ diff --git a/LFLiveKit/packet/flv/avc.c b/LFLiveKit/packet/flv/avc.c deleted file mode 100755 index ee0e95fe..00000000 --- a/LFLiveKit/packet/flv/avc.c +++ /dev/null @@ -1,298 +0,0 @@ -/* - $Id: avc.c 231 2011-06-27 13:46:19Z marc.noirot $ - - FLV Metadata updater - - Copyright (C) 2007-2012 Marc Noirot - - This file is part of FLVMeta. - - FLVMeta is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - FLVMeta 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 General Public License - along with FLVMeta; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#include - -#include "avc.h" - -/** - bit buffer handling -*/ -typedef struct __bit_buffer { - byte * start; - size_t size; - byte * current; - uint8 read_bits; -} bit_buffer; - -static void skip_bits(bit_buffer * bb, size_t nbits) { - bb->current = bb->current + ((nbits + bb->read_bits) / 8); - bb->read_bits = (uint8)((bb->read_bits + nbits) % 8); -} - -static uint8 get_bit(bit_buffer * bb) { - uint8 ret; - ret = (*(bb->current) >> (7 - bb->read_bits)) & 0x1; - if (bb->read_bits == 7) { - bb->read_bits = 0; - bb->current++; - } - else { - bb->read_bits++; - } - return ret; -} - -static uint32 get_bits(bit_buffer * bb, size_t nbits) { - uint32 i, ret; - ret = 0; - for (i = 0; i < nbits; i++) { - ret = (ret << 1) + get_bit(bb); - } - return ret; -} - -static uint32 exp_golomb_ue(bit_buffer * bb) { - uint8 bit, significant_bits; - significant_bits = 0; - bit = get_bit(bb); - while (bit == 0) { - significant_bits++; - bit = get_bit(bb); - } - return (1 << significant_bits) + get_bits(bb, significant_bits) - 1; -} - -static sint32 exp_golomb_se(bit_buffer * bb) { - sint32 ret; - ret = exp_golomb_ue(bb); - if ((ret & 0x1) == 0) { - return -(ret >> 1); - } - else { - return (ret + 1) >> 1; - } -} - -/* AVC type definitions */ - -#define AVC_SEQUENCE_HEADER 0 -#define AVC_NALU 1 -#define AVC_END_OF_SEQUENCE 2 - -typedef struct __AVCDecoderConfigurationRecord { - uint8 configurationVersion; - uint8 AVCProfileIndication; - uint8 profile_compatibility; - uint8 AVCLevelIndication; - uint8 lengthSizeMinusOne; - uint8 numOfSequenceParameterSets; -} AVCDecoderConfigurationRecord; - -int read_avc_decoder_configuration_record(flv_stream * f, AVCDecoderConfigurationRecord * adcr) { - if (flv_read_tag_body(f, &adcr->configurationVersion, 1) == 1 - && flv_read_tag_body(f, &adcr->AVCProfileIndication, 1) == 1 - && flv_read_tag_body(f, &adcr->profile_compatibility, 1) == 1 - && flv_read_tag_body(f, &adcr->AVCLevelIndication, 1) == 1 - && flv_read_tag_body(f, &adcr->lengthSizeMinusOne, 1) == 1 - && flv_read_tag_body(f, &adcr->numOfSequenceParameterSets, 1) == 1) { - return FLV_OK; - } - else { - return FLV_ERROR_EOF; - } -} - - -static void parse_scaling_list(uint32 size, bit_buffer * bb) { - uint32 last_scale, next_scale, i; - sint32 delta_scale; - last_scale = 8; - next_scale = 8; - for (i = 0; i < size; i++) { - if (next_scale != 0) { - delta_scale = exp_golomb_se(bb); - next_scale = (last_scale + delta_scale + 256) % 256; - } - if (next_scale != 0) { - last_scale = next_scale; - } - } -} - -/** - Parses a SPS NALU to retrieve video width and height -*/ -static void parse_sps(byte * sps, size_t sps_size, uint32 * width, uint32 * height) { - bit_buffer bb; - uint32 profile, pic_order_cnt_type, width_in_mbs, height_in_map_units; - uint32 i, size, left, right, top, bottom; - uint8 frame_mbs_only_flag; - - bb.start = sps; - bb.size = sps_size; - bb.current = sps; - bb.read_bits = 0; - - /* skip first byte, since we already know we're parsing a SPS */ - skip_bits(&bb, 8); - /* get profile */ - profile = get_bits(&bb, 8); - /* skip 4 bits + 4 zeroed bits + 8 bits = 32 bits = 4 bytes */ - skip_bits(&bb, 16); - - /* read sps id, first exp-golomb encoded value */ - exp_golomb_ue(&bb); - - if (profile == 100 || profile == 110 || profile == 122 || profile == 144) { - /* chroma format idx */ - if (exp_golomb_ue(&bb) == 3) { - skip_bits(&bb, 1); - } - /* bit depth luma minus8 */ - exp_golomb_ue(&bb); - /* bit depth chroma minus8 */ - exp_golomb_ue(&bb); - /* Qpprime Y Zero Transform Bypass flag */ - skip_bits(&bb, 1); - /* Seq Scaling Matrix Present Flag */ - if (get_bit(&bb)) { - for (i = 0; i < 8; i++) { - /* Seq Scaling List Present Flag */ - if (get_bit(&bb)) { - parse_scaling_list(i < 6 ? 16 : 64, &bb); - } - } - } - } - /* log2_max_frame_num_minus4 */ - exp_golomb_ue(&bb); - /* pic_order_cnt_type */ - pic_order_cnt_type = exp_golomb_ue(&bb); - if (pic_order_cnt_type == 0) { - /* log2_max_pic_order_cnt_lsb_minus4 */ - exp_golomb_ue(&bb); - } - else if (pic_order_cnt_type == 1) { - /* delta_pic_order_always_zero_flag */ - skip_bits(&bb, 1); - /* offset_for_non_ref_pic */ - exp_golomb_se(&bb); - /* offset_for_top_to_bottom_field */ - exp_golomb_se(&bb); - size = exp_golomb_ue(&bb); - for (i = 0; i < size; i++) { - /* offset_for_ref_frame */ - exp_golomb_se(&bb); - } - } - /* num_ref_frames */ - exp_golomb_ue(&bb); - /* gaps_in_frame_num_value_allowed_flag */ - skip_bits(&bb, 1); - /* pic_width_in_mbs */ - width_in_mbs = exp_golomb_ue(&bb) + 1; - /* pic_height_in_map_units */ - height_in_map_units = exp_golomb_ue(&bb) + 1; - /* frame_mbs_only_flag */ - frame_mbs_only_flag = get_bit(&bb); - if (!frame_mbs_only_flag) { - /* mb_adaptive_frame_field */ - skip_bits(&bb, 1); - } - /* direct_8x8_inference_flag */ - skip_bits(&bb, 1); - /* frame_cropping */ - left = right = top = bottom = 0; - if (get_bit(&bb)) { - left = exp_golomb_ue(&bb) * 2; - right = exp_golomb_ue(&bb) * 2; - top = exp_golomb_ue(&bb) * 2; - bottom = exp_golomb_ue(&bb) * 2; - if (!frame_mbs_only_flag) { - top *= 2; - bottom *= 2; - } - } - /* width */ - *width = width_in_mbs * 16 - (left + right); - /* height */ - *height = height_in_map_units * 16 - (top + bottom); - if (!frame_mbs_only_flag) { - *height *= 2; - } -} - -/** - Tries to read the resolution of the current video packet. - We assume to be at the first byte of the video data. -*/ -int read_avc_resolution(flv_stream * f, uint32 body_length, uint32 * width, uint32 * height) { - byte avc_packet_type; - uint24 composition_time; - AVCDecoderConfigurationRecord adcr; - uint16 sps_size; - byte * sps_buffer; - - /* make sure we have enough bytes to read in the current tag */ - if (body_length < sizeof(byte) + sizeof(uint24) + sizeof(AVCDecoderConfigurationRecord)) { - return FLV_OK; - } - - /* determine whether we're reading an AVCDecoderConfigurationRecord */ - if (flv_read_tag_body(f, &avc_packet_type, 1) < 1) { - return FLV_ERROR_EOF; - } - if (avc_packet_type != AVC_SEQUENCE_HEADER) { - return FLV_OK; - } - - /* read the composition time */ - if (flv_read_tag_body(f, &composition_time, sizeof(uint24)) < sizeof(uint24)) { - return FLV_ERROR_EOF; - } - - /* we need to read an AVCDecoderConfigurationRecord */ - if (read_avc_decoder_configuration_record(f, &adcr) == FLV_ERROR_EOF) { - return FLV_ERROR_EOF; - } - - /* number of SequenceParameterSets */ - if ((adcr.numOfSequenceParameterSets & 0x1F) == 0) { - /* no SPS, return */ - return FLV_OK; - } - - /** read the first SequenceParameterSet found */ - /* SPS size */ - if (flv_read_tag_body(f, &sps_size, sizeof(uint16)) < sizeof(uint16)) { - return FLV_ERROR_EOF; - } - sps_size = swap_uint16(sps_size); - - /* read the SPS entirely */ - sps_buffer = (byte *) malloc((size_t)sps_size); - if (sps_buffer == NULL) { - return FLV_ERROR_MEMORY; - } - if (flv_read_tag_body(f, sps_buffer, (size_t)sps_size) < (size_t)sps_size) { - free(sps_buffer); - return FLV_ERROR_EOF; - } - - /* parse SPS to determine video resolution */ - parse_sps(sps_buffer, (size_t)sps_size, width, height); - - free(sps_buffer); - return FLV_OK; -} diff --git a/LFLiveKit/packet/flv/avc.h b/LFLiveKit/packet/flv/avc.h deleted file mode 100755 index 833706f7..00000000 --- a/LFLiveKit/packet/flv/avc.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - $Id: avc.h 231 2011-06-27 13:46:19Z marc.noirot $ - - FLV Metadata updater - - Copyright (C) 2007-2012 Marc Noirot - - This file is part of FLVMeta. - - FLVMeta is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - FLVMeta 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 General Public License - along with FLVMeta; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#ifndef __AVC_H__ -#define __AVC_H__ - -#include - -#include "types.h" -#include "flv.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -int read_avc_resolution(flv_stream * f, uint32 body_length, uint32 * width, uint32 * height); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __AVC_H__ */ diff --git a/LFLiveKit/packet/flv/flv.c b/LFLiveKit/packet/flv/flv.c deleted file mode 100755 index 5ea4516c..00000000 --- a/LFLiveKit/packet/flv/flv.c +++ /dev/null @@ -1,498 +0,0 @@ -/* - $Id: flv.c 231 2011-06-27 13:46:19Z marc.noirot $ - - FLV Metadata updater - - Copyright (C) 2007-2012 Marc Noirot - - This file is part of FLVMeta. - - FLVMeta is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - FLVMeta 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 General Public License - along with FLVMeta; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#include "flv.h" - -#include - -void flv_tag_set_timestamp(flv_tag * tag, uint32 timestamp) { - tag->timestamp = uint32_to_uint24_be(timestamp); - tag->timestamp_extended = (uint8)((timestamp & 0xFF000000) >> 24); -} - -/* FLV stream functions */ -flv_stream * flv_open(const char * file) { - flv_stream * stream = (flv_stream *) malloc(sizeof(flv_stream)); - if (stream == NULL) { - return NULL; - } - stream->flvin = fopen(file, "rb"); - if (stream->flvin == NULL) { - free(stream); - return NULL; - } - stream->current_tag_body_length = 0; - stream->current_tag_body_overflow = 0; - stream->current_tag_offset = 0; - stream->state = FLV_STREAM_STATE_START; - return stream; -} - -int flv_read_header(flv_stream * stream, flv_header * header) { - if (stream == NULL - || stream->flvin == NULL - || feof(stream->flvin) - || stream->state != FLV_STREAM_STATE_START) { - return FLV_ERROR_EOF; - } - - if (fread(&header->signature, sizeof(header->signature), 1, stream->flvin) == 0 - || fread(&header->version, sizeof(header->version), 1, stream->flvin) == 0 - || fread(&header->flags, sizeof(header->flags), 1, stream->flvin) == 0 - || fread(&header->offset, sizeof(header->offset), 1, stream->flvin) == 0) { - return FLV_ERROR_EOF; - } - - if (header->signature[0] != 'F' - || header->signature[1] != 'L' - || header->signature[2] != 'V') { - return FLV_ERROR_NO_FLV; - } - - stream->state = FLV_STREAM_STATE_PREV_TAG_SIZE; - return FLV_OK; -} - -int flv_read_prev_tag_size(flv_stream * stream, uint32 * prev_tag_size) { - uint32_be val; - if (stream == NULL - || stream->flvin == NULL - || feof(stream->flvin)) { - return FLV_ERROR_EOF; - } - - /* skip remaining tag body bytes */ - if (stream->state == FLV_STREAM_STATE_TAG_BODY) { - lfs_fseek(stream->flvin, stream->current_tag_offset + FLV_TAG_SIZE + uint24_be_to_uint32(stream->current_tag.body_length), SEEK_SET); - stream->state = FLV_STREAM_STATE_PREV_TAG_SIZE; - } - - if (stream->state == FLV_STREAM_STATE_PREV_TAG_SIZE) { - if (fread(&val, sizeof(uint32_be), 1, stream->flvin) == 0) { - return FLV_ERROR_EOF; - } - else { - stream->state = FLV_STREAM_STATE_TAG; - *prev_tag_size = swap_uint32(val); - return FLV_OK; - } - } - else { - return FLV_ERROR_EOF; - } -} - -int flv_read_tag(flv_stream * stream, flv_tag * tag) { - if (stream == NULL - || stream->flvin == NULL - || feof(stream->flvin)) { - return FLV_ERROR_EOF; - } - - /* skip header */ - if (stream->state == FLV_STREAM_STATE_START) { - lfs_fseek(stream->flvin, FLV_HEADER_SIZE, SEEK_CUR); - stream->state = FLV_STREAM_STATE_PREV_TAG_SIZE; - } - - /* skip current tag body */ - if (stream->state == FLV_STREAM_STATE_TAG_BODY) { - lfs_fseek(stream->flvin, stream->current_tag_offset + FLV_TAG_SIZE + uint24_be_to_uint32(stream->current_tag.body_length), SEEK_SET); - stream->state = FLV_STREAM_STATE_PREV_TAG_SIZE; - } - - /* skip previous tag size */ - if (stream->state == FLV_STREAM_STATE_PREV_TAG_SIZE) { - lfs_fseek(stream->flvin, sizeof(uint32_be), SEEK_CUR); - stream->state = FLV_STREAM_STATE_TAG; - } - - if (stream->state == FLV_STREAM_STATE_TAG) { - stream->current_tag_offset = lfs_ftell(stream->flvin); - - if (fread(&tag->type, sizeof(tag->type), 1, stream->flvin) == 0 - || fread(&tag->body_length, sizeof(tag->body_length), 1, stream->flvin) == 0 - || fread(&tag->timestamp, sizeof(tag->timestamp), 1, stream->flvin) == 0 - || fread(&tag->timestamp_extended, sizeof(tag->timestamp_extended), 1, stream->flvin) == 0 - || fread(&tag->stream_id, sizeof(tag->stream_id), 1, stream->flvin) == 0) { - return FLV_ERROR_EOF; - } - else { - memcpy(&stream->current_tag, tag, sizeof(flv_tag)); - stream->current_tag_body_length = uint24_be_to_uint32(tag->body_length); - stream->current_tag_body_overflow = 0; - stream->state = FLV_STREAM_STATE_TAG_BODY; - return FLV_OK; - } - } - else { - return FLV_ERROR_EOF; - } -} - -int flv_read_audio_tag(flv_stream * stream, flv_audio_tag * tag) { - if (stream == NULL - || stream->flvin == NULL - || feof(stream->flvin) - || stream->state != FLV_STREAM_STATE_TAG_BODY) { - return FLV_ERROR_EOF; - } - - if (stream->current_tag_body_length == 0) { - return FLV_ERROR_EMPTY_TAG; - } - - if (fread(tag, sizeof(flv_audio_tag), 1, stream->flvin) == 0) { - return FLV_ERROR_EOF; - } - - if (stream->current_tag_body_length >= sizeof(flv_audio_tag)) { - stream->current_tag_body_length -= sizeof(flv_audio_tag); - } - else { - stream->current_tag_body_overflow = sizeof(flv_audio_tag) - stream->current_tag_body_length; - stream->current_tag_body_length = 0; - } - - if (stream->current_tag_body_length == 0) { - stream->state = FLV_STREAM_STATE_PREV_TAG_SIZE; - if (stream->current_tag_body_overflow > 0) { - lfs_fseek(stream->flvin, -(file_offset_t)stream->current_tag_body_overflow, SEEK_CUR); - } - } - - return FLV_OK; -} - -int flv_read_video_tag(flv_stream * stream, flv_video_tag * tag) { - if (stream == NULL - || stream->flvin == NULL - || feof(stream->flvin) - || stream->state != FLV_STREAM_STATE_TAG_BODY) { - return FLV_ERROR_EOF; - } - - if (stream->current_tag_body_length == 0) { - return FLV_ERROR_EMPTY_TAG; - } - - if (fread(tag, sizeof(flv_video_tag), 1, stream->flvin) == 0) { - return FLV_ERROR_EOF; - } - - if (stream->current_tag_body_length >= sizeof(flv_video_tag)) { - stream->current_tag_body_length -= sizeof(flv_video_tag); - } - else { - stream->current_tag_body_overflow = sizeof(flv_video_tag) - stream->current_tag_body_length; - stream->current_tag_body_length = 0; - } - - if (stream->current_tag_body_length == 0) { - stream->state = FLV_STREAM_STATE_PREV_TAG_SIZE; - if (stream->current_tag_body_overflow > 0) { - lfs_fseek(stream->flvin, -(file_offset_t)stream->current_tag_body_overflow, SEEK_CUR); - } - } - - return FLV_OK; -} - -int flv_read_metadata(flv_stream * stream, amf_data ** name, amf_data ** data) { - amf_data * d; - byte error_code; - size_t data_size; - - if (stream == NULL - || stream->flvin == NULL - || feof(stream->flvin) - || stream->state != FLV_STREAM_STATE_TAG_BODY) { - return FLV_ERROR_EOF; - } - - if (stream->current_tag_body_length == 0) { - return FLV_ERROR_EMPTY_TAG; - } - - /* read metadata name */ - d = amf_data_file_read(stream->flvin); - *name = d; - error_code = amf_data_get_error_code(d); - if (error_code == AMF_ERROR_EOF) { - return FLV_ERROR_EOF; - } - else if (error_code != AMF_ERROR_OK) { - return FLV_ERROR_INVALID_METADATA_NAME; - } - - /* if only name can be read, metadata are invalid */ - data_size = amf_data_size(d); - if (stream->current_tag_body_length > data_size) { - stream->current_tag_body_length -= (uint32)data_size; - } - else { - stream->current_tag_body_length = 0; - stream->current_tag_body_overflow = (uint32)data_size - stream->current_tag_body_length; - - stream->state = FLV_STREAM_STATE_PREV_TAG_SIZE; - if (stream->current_tag_body_overflow > 0) { - lfs_fseek(stream->flvin, -(file_offset_t)stream->current_tag_body_overflow, SEEK_CUR); - } - - return FLV_ERROR_INVALID_METADATA; - } - - /* read metadata contents */ - d = amf_data_file_read(stream->flvin); - *data = d; - error_code = amf_data_get_error_code(d); - if (error_code == AMF_ERROR_EOF) { - return FLV_ERROR_EOF; - } - if (error_code != AMF_ERROR_OK) { - return FLV_ERROR_INVALID_METADATA; - } - - data_size = amf_data_size(d); - if (stream->current_tag_body_length >= data_size) { - stream->current_tag_body_length -= (uint32)data_size; - } - else { - stream->current_tag_body_overflow = (uint32)data_size - stream->current_tag_body_length; - stream->current_tag_body_length = 0; - } - - if (stream->current_tag_body_length == 0) { - stream->state = FLV_STREAM_STATE_PREV_TAG_SIZE; - if (stream->current_tag_body_overflow > 0) { - lfs_fseek(stream->flvin, -(file_offset_t)stream->current_tag_body_overflow, SEEK_CUR); - } - } - - return FLV_OK; -} - -size_t flv_read_tag_body(flv_stream * stream, void * buffer, size_t buffer_size) { - size_t bytes_number; - - if (stream == NULL - || stream->flvin == NULL - || feof(stream->flvin) - || stream->state != FLV_STREAM_STATE_TAG_BODY) { - return 0; - } - - bytes_number = (buffer_size > stream->current_tag_body_length) ? stream->current_tag_body_length : buffer_size; - bytes_number = fread(buffer, sizeof(byte), bytes_number, stream->flvin); - - stream->current_tag_body_length -= (uint32)bytes_number; - - if (stream->current_tag_body_length == 0) { - stream->state = FLV_STREAM_STATE_PREV_TAG_SIZE; - } - - return bytes_number; -} - -file_offset_t flv_get_current_tag_offset(flv_stream * stream) { - return (stream != NULL) ? stream->current_tag_offset : 0; -} - -file_offset_t flv_get_offset(flv_stream * stream) { - return (stream != NULL) ? lfs_ftell(stream->flvin) : 0; -} - -void flv_reset(flv_stream * stream) { - /* go back to beginning of file */ - if (stream != NULL && stream->flvin != NULL) { - stream->current_tag_body_length = 0; - stream->current_tag_offset = 0; - stream->state = FLV_STREAM_STATE_START; - - lfs_fseek(stream->flvin, 0, SEEK_SET); - } -} - -void flv_close(flv_stream * stream) { - if (stream != NULL) { - if (stream->flvin != NULL) { - fclose(stream->flvin); - } - free(stream); - } -} - -/* FLV stdio writing helper functions */ -size_t flv_write_header(FILE * out, const flv_header * header) { - if (fwrite(&header->signature, sizeof(header->signature), 1, out) == 0) - return 0; - if (fwrite(&header->version, sizeof(header->version), 1, out) == 0) - return 0; - if (fwrite(&header->flags, sizeof(header->flags), 1, out) == 0) - return 0; - if (fwrite(&header->offset, sizeof(header->offset), 1, out) == 0) - return 0; - return 1; -} - -size_t flv_write_tag(FILE * out, const flv_tag * tag) { - if (fwrite(&tag->type, sizeof(tag->type), 1, out) == 0) - return 0; - - if (fwrite(&tag->body_length, sizeof(tag->body_length), 1, out) == 0) - return 0; - - if (fwrite(&tag->timestamp, sizeof(tag->timestamp), 1, out) == 0) - return 0; - if (fwrite(&tag->timestamp_extended, sizeof(tag->timestamp_extended), 1, out) == 0) - return 0; - if (fwrite(&tag->stream_id, sizeof(tag->stream_id), 1, out) == 0) - return 0; - return 1; -} - -/* FLV event based parser */ -int flv_parse(const char * file, flv_parser * parser) { - flv_header header; - flv_tag tag; - flv_audio_tag at; - flv_video_tag vt; - amf_data * name, * data; - uint32 prev_tag_size; - int retval; - - if (parser == NULL) { - return FLV_ERROR_EOF; - } - - parser->stream = flv_open(file); - if (parser->stream == NULL) { - return FLV_ERROR_OPEN_READ; - } - - retval = flv_read_header(parser->stream, &header); - if (retval != FLV_OK) { - flv_close(parser->stream); - return retval; - } - - if (parser->on_header != NULL) { - retval = parser->on_header(&header, parser); - if (retval != FLV_OK) { - flv_close(parser->stream); - return retval; - } - } - - while (flv_read_tag(parser->stream, &tag) == FLV_OK) { - if (parser->on_tag != NULL) { - retval = parser->on_tag(&tag, parser); - if (retval != FLV_OK) { - flv_close(parser->stream); - return retval; - } - } - - if (tag.type == FLV_TAG_TYPE_AUDIO) { - retval = flv_read_audio_tag(parser->stream, &at); - if (retval == FLV_ERROR_EOF) { - flv_close(parser->stream); - return retval; - } - if (retval != FLV_ERROR_EMPTY_TAG && parser->on_audio_tag != NULL) { - retval = parser->on_audio_tag(&tag, at, parser); - if (retval != FLV_OK) { - flv_close(parser->stream); - return retval; - } - } - } - else if (tag.type == FLV_TAG_TYPE_VIDEO) { - retval = flv_read_video_tag(parser->stream, &vt); - if (retval == FLV_ERROR_EOF) { - flv_close(parser->stream); - return retval; - } - if (retval != FLV_ERROR_EMPTY_TAG && parser->on_video_tag != NULL) { - retval = parser->on_video_tag(&tag, vt, parser); - if (retval != FLV_OK) { - flv_close(parser->stream); - return retval; - } - } - } - else if (tag.type == FLV_TAG_TYPE_META) { - name = data = NULL; - retval = flv_read_metadata(parser->stream, &name, &data); - if (retval == FLV_ERROR_EOF) { - amf_data_free(name); - amf_data_free(data); - flv_close(parser->stream); - return retval; - } - else if (retval == FLV_OK && parser->on_metadata_tag != NULL) { - retval = parser->on_metadata_tag(&tag, name, data, parser); - if (retval != FLV_OK) { - amf_data_free(name); - amf_data_free(data); - flv_close(parser->stream); - return retval; - } - } - amf_data_free(name); - amf_data_free(data); - } - else { - if (parser->on_unknown_tag != NULL) { - retval = parser->on_unknown_tag(&tag, parser); - if (retval != FLV_OK) { - flv_close(parser->stream); - return retval; - } - } - } - retval = flv_read_prev_tag_size(parser->stream, &prev_tag_size); - if (retval != FLV_OK) { - flv_close(parser->stream); - return retval; - } - if (parser->on_prev_tag_size != NULL) { - retval = parser->on_prev_tag_size(prev_tag_size, parser); - if (retval != FLV_OK) { - flv_close(parser->stream); - return retval; - } - } - } - - if (parser->on_stream_end != NULL) { - retval = parser->on_stream_end(parser); - if (retval != FLV_OK) { - flv_close(parser->stream); - return retval; - } - } - - flv_close(parser->stream); - return FLV_OK; -} diff --git a/LFLiveKit/packet/flv/flv.h b/LFLiveKit/packet/flv/flv.h deleted file mode 100755 index 1f9b5232..00000000 --- a/LFLiveKit/packet/flv/flv.h +++ /dev/null @@ -1,202 +0,0 @@ -/* - $Id: flv.h 231 2011-06-27 13:46:19Z marc.noirot $ - - FLV Metadata updater - - Copyright (C) 2007-2012 Marc Noirot - - This file is part of FLVMeta. - - FLVMeta is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - FLVMeta 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 General Public License - along with FLVMeta; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#ifndef __FLV_H__ -#define __FLV_H__ - -/* Configuration of the sources */ -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "types.h" -#include "amf.h" - -/* error statuses */ -#define FLV_OK 0 -#define FLV_ERROR_OPEN_READ 1 -#define FLV_ERROR_NO_FLV 2 -#define FLV_ERROR_EOF 3 -#define FLV_ERROR_MEMORY 4 -#define FLV_ERROR_EMPTY_TAG 5 -#define FLV_ERROR_INVALID_METADATA_NAME 6 -#define FLV_ERROR_INVALID_METADATA 7 - -/* flv file format structure and definitions */ - -/* FLV file header */ -#define FLV_SIGNATURE "FLV" -#define FLV_VERSION ((uint8)0x01) - -#define FLV_FLAG_VIDEO ((uint8)0x01) -#define FLV_FLAG_AUDIO ((uint8)0x04) - -typedef struct __flv_header { - byte signature[3]; /* always "FLV" */ - uint8 version; /* should be 1 */ - uint8_bitmask flags; - uint32_be offset; /* always 9 */ -} flv_header; - -#define FLV_HEADER_SIZE 9 - -#define flv_header_has_video(header) ((header).flags & FLV_FLAG_VIDEO) -#define flv_header_has_audio(header) ((header).flags & FLV_FLAG_AUDIO) -#define flv_header_get_offset(header) (swap_uint32((header).offset)) - -/* FLV tag */ -#define FLV_TAG_TYPE_AUDIO ((uint8)0x08) -#define FLV_TAG_TYPE_VIDEO ((uint8)0x09) -#define FLV_TAG_TYPE_META ((uint8)0x12) - -typedef struct __flv_tag { - uint8 type; - uint24_be body_length; /* in bytes, total tag size minus 11 */ - uint24_be timestamp; /* milli-seconds */ - uint8 timestamp_extended; /* timestamp extension */ - uint24_be stream_id; /* reserved, must be "\0\0\0" */ - /* body comes next */ -} flv_tag; - -#define FLV_TAG_SIZE 11 - -#define flv_tag_get_body_length(tag) (uint24_be_to_uint32((tag).body_length)) -#define flv_tag_get_timestamp(tag) \ - (uint24_be_to_uint32((tag).timestamp) + ((tag).timestamp_extended << 24)) -#define flv_tag_get_stream_id(tag) (uint24_be_to_uint32((tag).stream_id)) - -/* audio tag */ -#define FLV_AUDIO_TAG_SOUND_TYPE_MONO 0 -#define FLV_AUDIO_TAG_SOUND_TYPE_STEREO 1 - -#define FLV_AUDIO_TAG_SOUND_SIZE_8 0 -#define FLV_AUDIO_TAG_SOUND_SIZE_16 1 - -#define FLV_AUDIO_TAG_SOUND_RATE_5_5 0 -#define FLV_AUDIO_TAG_SOUND_RATE_11 1 -#define FLV_AUDIO_TAG_SOUND_RATE_22 2 -#define FLV_AUDIO_TAG_SOUND_RATE_44 3 - -#define FLV_AUDIO_TAG_SOUND_FORMAT_LINEAR_PCM 0 -#define FLV_AUDIO_TAG_SOUND_FORMAT_ADPCM 1 -#define FLV_AUDIO_TAG_SOUND_FORMAT_MP3 2 -#define FLV_AUDIO_TAG_SOUND_FORMAT_LINEAR_PCM_LE 3 -#define FLV_AUDIO_TAG_SOUND_FORMAT_NELLYMOSER_16_MONO 4 -#define FLV_AUDIO_TAG_SOUND_FORMAT_NELLYMOSER_8_MONO 5 -#define FLV_AUDIO_TAG_SOUND_FORMAT_NELLYMOSER 6 -#define FLV_AUDIO_TAG_SOUND_FORMAT_G711_A 7 -#define FLV_AUDIO_TAG_SOUND_FORMAT_G711_MU 8 -#define FLV_AUDIO_TAG_SOUND_FORMAT_RESERVED 9 -#define FLV_AUDIO_TAG_SOUND_FORMAT_AAC 10 -#define FLV_AUDIO_TAG_SOUND_FORMAT_SPEEX 11 -#define FLV_AUDIO_TAG_SOUND_FORMAT_MP3_8 14 -#define FLV_AUDIO_TAG_SOUND_FORMAT_DEVICE_SPECIFIC 15 - -typedef byte flv_audio_tag; - -#define flv_audio_tag_sound_type(tag) (((tag) & 0x01) >> 0) -#define flv_audio_tag_sound_size(tag) (((tag) & 0x02) >> 1) -#define flv_audio_tag_sound_rate(tag) (((tag) & 0x0C) >> 2) -#define flv_audio_tag_sound_format(tag) (((tag) & 0xF0) >> 4) - -/* video tag */ -#define FLV_VIDEO_TAG_CODEC_JPEG 1 -#define FLV_VIDEO_TAG_CODEC_SORENSEN_H263 2 -#define FLV_VIDEO_TAG_CODEC_SCREEN_VIDEO 3 -#define FLV_VIDEO_TAG_CODEC_ON2_VP6 4 -#define FLV_VIDEO_TAG_CODEC_ON2_VP6_ALPHA 5 -#define FLV_VIDEO_TAG_CODEC_SCREEN_VIDEO_V2 6 -#define FLV_VIDEO_TAG_CODEC_AVC 7 - -#define FLV_VIDEO_TAG_FRAME_TYPE_KEYFRAME 1 -#define FLV_VIDEO_TAG_FRAME_TYPE_INTERFRAME 2 -#define FLV_VIDEO_TAG_FRAME_TYPE_DISPOSABLE_INTERFRAME 3 -#define FLV_VIDEO_TAG_FRAME_TYPE_GENERATED_KEYFRAME 4 -#define FLV_VIDEO_TAG_FRAME_TYPE_COMMAND_FRAME 5 - -typedef byte flv_video_tag; - -#define flv_video_tag_codec_id(tag) (((tag) & 0x0F) >> 0) -#define flv_video_tag_frame_type(tag) (((tag) & 0xF0) >> 4) - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* FLV helper functions */ -void flv_tag_set_timestamp(flv_tag * tag, uint32 timestamp); - -/* FLV stream */ -#define FLV_STREAM_STATE_START 0 -#define FLV_STREAM_STATE_TAG 1 -#define FLV_STREAM_STATE_TAG_BODY 2 -#define FLV_STREAM_STATE_PREV_TAG_SIZE 3 - -typedef struct __flv_stream { - FILE * flvin; - uint8 state; - flv_tag current_tag; - file_offset_t current_tag_offset; - uint32 current_tag_body_length; - uint32 current_tag_body_overflow; -} flv_stream; - -/* FLV stream functions */ -flv_stream * flv_open(const char * file); -int flv_read_header(flv_stream * stream, flv_header * header); -int flv_read_prev_tag_size(flv_stream * stream, uint32 * prev_tag_size); -int flv_read_tag(flv_stream * stream, flv_tag * tag); -int flv_read_audio_tag(flv_stream * stream, flv_audio_tag * tag); -int flv_read_video_tag(flv_stream * stream, flv_video_tag * tag); -int flv_read_metadata(flv_stream * stream, amf_data ** name, amf_data ** data); -size_t flv_read_tag_body(flv_stream * stream, void * buffer, size_t buffer_size); -file_offset_t flv_get_current_tag_offset(flv_stream * stream); -file_offset_t flv_get_offset(flv_stream * stream); -void flv_reset(flv_stream * stream); -void flv_close(flv_stream * stream); - -/* FLV stdio writing helper functions */ -size_t flv_write_header(FILE * out, const flv_header * header); -size_t flv_write_tag(FILE * out, const flv_tag * tag); - -/* FLV event based parser */ -typedef struct __flv_parser { - flv_stream * stream; - void * user_data; - int (* on_header)(flv_header * header, struct __flv_parser * parser); - int (* on_tag)(flv_tag * tag, struct __flv_parser * parser); - int (* on_metadata_tag)(flv_tag * tag, amf_data * name, amf_data * data, struct __flv_parser * parser); - int (* on_audio_tag)(flv_tag * tag, flv_audio_tag audio_tag, struct __flv_parser * parser); - int (* on_video_tag)(flv_tag * tag, flv_video_tag audio_tag, struct __flv_parser * parser); - int (* on_unknown_tag)(flv_tag * tag, struct __flv_parser * parser); - int (* on_prev_tag_size)(uint32 size, struct __flv_parser * parser); - int (* on_stream_end)(struct __flv_parser * parser); -} flv_parser; - -int flv_parse(const char * file, flv_parser * parser); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __FLV_H__ */ diff --git a/LFLiveKit/packet/flv/info.c b/LFLiveKit/packet/flv/info.c deleted file mode 100755 index e8f099df..00000000 --- a/LFLiveKit/packet/flv/info.c +++ /dev/null @@ -1,626 +0,0 @@ -/* - $Id: info.c 231 2011-06-27 13:46:19Z marc.noirot $ - - FLV Metadata updater - - Copyright (C) 2007-2012 Marc Noirot - - This file is part of FLVMeta. - - FLVMeta is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - FLVMeta 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 General Public License - along with FLVMeta; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#include "info.h" -#include "avc.h" - -#include - -#pragma warning(disable:4244) -/* - compute Sorensen H.263 video size -*/ -static int compute_h263_size(flv_stream * flv_in, flv_info * info, uint32 body_length) { - byte header[9]; - uint24_be psc_be; - uint32 psc; - - /* make sure we have enough bytes to read in the current tag */ - if (body_length >= 9) { - if (flv_read_tag_body(flv_in, header, 9) < 9) { - return FLV_ERROR_EOF; - } - psc_be.b[0] = header[0]; - psc_be.b[1] = header[1]; - psc_be.b[2] = header[2]; - psc = uint24_be_to_uint32(psc_be) >> 7; - if (psc == 1) { - uint32 psize = ((header[3] & 0x03) << 1) + ((header[4] >> 7) & 0x01); - switch (psize) { - case 0: - info->video_width = ((header[4] & 0x7f) << 1) + ((header[5] >> 7) & 0x01); - info->video_height = ((header[5] & 0x7f) << 1) + ((header[6] >> 7) & 0x01); - break; - case 1: - info->video_width = ((header[4] & 0x7f) << 9) + (header[5] << 1) + ((header[6] >> 7) & 0x01); - info->video_height = ((header[6] & 0x7f) << 9) + (header[7] << 1) + ((header[8] >> 7) & 0x01); - break; - case 2: - info->video_width = 352; - info->video_height = 288; - break; - case 3: - info->video_width = 176; - info->video_height = 144; - break; - case 4: - info->video_width = 128; - info->video_height = 96; - break; - case 5: - info->video_width = 320; - info->video_height = 240; - break; - case 6: - info->video_width = 160; - info->video_height = 120; - break; - default: - break; - } - } - } - return FLV_OK; -} - -/* - compute Screen video size -*/ -static int compute_screen_size(flv_stream * flv_in, flv_info * info, uint32 body_length) { - byte header[4]; - - /* make sure we have enough bytes to read in the current tag */ - if (body_length >= 4) { - if (flv_read_tag_body(flv_in, header, 4) < 4) { - return FLV_ERROR_EOF; - } - - info->video_width = ((header[0] & 0x0f) << 8) + header[1]; - info->video_height = ((header[2] & 0x0f) << 8) + header[3]; - } - return FLV_OK; -} - -/* - compute On2 VP6 video size -*/ -static int compute_vp6_size(flv_stream * flv_in, flv_info * info, uint32 body_length) { - byte header[7], offset; - - /* make sure we have enough bytes to read in the current tag */ - if (body_length >= 7) { - if (flv_read_tag_body(flv_in, header, 7) < 7) { - return FLV_ERROR_EOF; - } - - /* two bytes offset if VP6 0 */ - offset = (header[1] & 0x01 || !(header[2] & 0x06)) << 1; - info->video_width = (header[4 + offset] << 4) - (header[0] >> 4); - info->video_height = (header[3 + offset] << 4) - (header[0] & 0x0f); - - } - return FLV_OK; -} - -/* - compute On2 VP6 with Alpha video size -*/ -static int compute_vp6_alpha_size(flv_stream * flv_in, flv_info * info, uint32 body_length) { - byte header[10], offset; - - /* make sure we have enough bytes to read in the current tag */ - if (body_length >= 10) { - if (flv_read_tag_body(flv_in, header, 10) < 10) { - return FLV_ERROR_EOF; - } - - /* two bytes offset if VP6 0 */ - offset = (header[4] & 0x01 || !(header[5] & 0x06)) << 1; - info->video_width = (header[7 + offset] << 4) - (header[0] >> 4); - info->video_height = (header[6 + offset] << 4) - (header[0] & 0x0f); - } - return FLV_OK; -} - -/* - compute AVC (H.264) video size (experimental) -*/ -static int compute_avc_size(flv_stream * flv_in, flv_info * info, uint32 body_length) { - return read_avc_resolution(flv_in, body_length, &(info->video_width), &(info->video_height)); -} - -/* - compute video width and height from the first video frame -*/ -static int compute_video_size(flv_stream * flv_in, flv_info * info, uint32 body_length) { - switch (info->video_codec) { - case FLV_VIDEO_TAG_CODEC_SORENSEN_H263: - return compute_h263_size(flv_in, info, body_length); - case FLV_VIDEO_TAG_CODEC_SCREEN_VIDEO: - case FLV_VIDEO_TAG_CODEC_SCREEN_VIDEO_V2: - return compute_screen_size(flv_in, info, body_length); - case FLV_VIDEO_TAG_CODEC_ON2_VP6: - return compute_vp6_size(flv_in, info, body_length); - case FLV_VIDEO_TAG_CODEC_ON2_VP6_ALPHA: - return compute_vp6_alpha_size(flv_in, info, body_length); - case FLV_VIDEO_TAG_CODEC_AVC: - return compute_avc_size(flv_in, info, body_length); - default: - return FLV_OK; - } -} - -/* - read the flv file thoroughly to get all necessary information. - - we need to check : - - timestamp of first audio for audio delay - - whether we have audio and video - - first frames codecs (audio, video) - - total audio and video data sizes - - keyframe offsets and timestamps - - whether the last video frame is a keyframe - - last keyframe timestamp - - onMetaData tag total size - - total tags size - - first tag after onMetaData offset - - last timestamp - - real video data size, number of frames, duration to compute framerate and video data rate - - real audio data size, duration to compute audio data rate - - video headers to find width and height. (depends on the encoding) -*/ -int get_flv_info(flv_stream * flv_in, flv_info * info) { - uint32 prev_timestamp_video; - uint32 prev_timestamp_audio; - uint32 prev_timestamp_meta; - uint8 timestamp_extended_video; - uint8 timestamp_extended_audio; - uint8 timestamp_extended_meta; - uint8 have_video_size; - uint8 have_first_timestamp; - uint32 tag_number; - int result; - flv_tag ft; - - info->have_video = 0; - info->have_audio = 0; - info->video_width = 0; - info->video_height = 0; - info->video_codec = 0; - info->video_frames_number = 0; - info->audio_codec = 0; - info->audio_size = 0; - info->audio_rate = 0; - info->audio_stereo = 0; - info->video_data_size = 0; - info->audio_data_size = 0; - info->meta_data_size = 0; - info->real_video_data_size = 0; - info->real_audio_data_size = 0; - info->video_first_timestamp = 0; - info->audio_first_timestamp = 0; - info->first_timestamp = 0; - info->can_seek_to_end = 0; - info->have_keyframes = 0; - info->last_keyframe_timestamp = 0; - info->on_metadata_size = 0; - info->on_metadata_offset = 0; - info->biggest_tag_body_size = 0; - info->last_timestamp = 0; - info->video_frame_duration = 0; - info->audio_frame_duration = 0; - info->total_prev_tags_size = 0; - info->have_on_last_second = 0; - info->original_on_metadata = NULL; - info->keyframes = NULL; - info->times = NULL; - info->filepositions = NULL; - - /* - read FLV header - */ - - if (flv_read_header(flv_in, &(info->header)) != FLV_OK) { - return FLV_ERROR_NO_FLV; - } - - info->keyframes = amf_object_new(); - info->times = amf_array_new(); - info->filepositions = amf_array_new(); - amf_object_add(info->keyframes, "times", info->times); - amf_object_add(info->keyframes, "filepositions", info->filepositions); - - /* first empty previous tag size */ - info->total_prev_tags_size = sizeof(uint32_be); - - /* first timestamp */ - have_first_timestamp = 0; - - /* extended timestamp initialization */ - prev_timestamp_video = 0; - prev_timestamp_audio = 0; - prev_timestamp_meta = 0; - timestamp_extended_video = 0; - timestamp_extended_audio = 0; - timestamp_extended_meta = 0; - tag_number = 0; - have_video_size = 0; - - while (flv_read_tag(flv_in, &ft) == FLV_OK) { - file_offset_t offset; - uint32 body_length; - uint32 timestamp; - - offset = flv_get_current_tag_offset(flv_in); - body_length = flv_tag_get_body_length(ft); - timestamp = flv_tag_get_timestamp(ft); - - /* extended timestamp fixing */ - if (ft.type == FLV_TAG_TYPE_META) { - if (timestamp < prev_timestamp_meta - && prev_timestamp_meta - timestamp > 0xF00000) { - ++timestamp_extended_meta; - } - prev_timestamp_meta = timestamp; - if (timestamp_extended_meta > 0) { - timestamp += timestamp_extended_meta << 24; - } - } - else if (ft.type == FLV_TAG_TYPE_AUDIO) { - if (timestamp < prev_timestamp_audio - && prev_timestamp_audio - timestamp > 0xF00000) { - ++timestamp_extended_audio; - } - prev_timestamp_audio = timestamp; - if (timestamp_extended_audio > 0) { - timestamp += timestamp_extended_audio << 24; - } - } - else if (ft.type == FLV_TAG_TYPE_VIDEO) { - if (timestamp < prev_timestamp_video - && prev_timestamp_video - timestamp > 0xF00000) { - ++timestamp_extended_video; - } - prev_timestamp_video = timestamp; - if (timestamp_extended_video > 0) { - timestamp += timestamp_extended_video << 24; - } - } - - /* non-zero starting timestamp handling */ - if (!have_first_timestamp && ft.type != FLV_TAG_TYPE_META) { - info->first_timestamp = timestamp; - have_first_timestamp = 1; - } - if (timestamp > 0) { - timestamp -= info->first_timestamp; - } - - /* update the info struct only if the tag is valid */ - if (ft.type == FLV_TAG_TYPE_META - || ft.type == FLV_TAG_TYPE_AUDIO - || ft.type == FLV_TAG_TYPE_VIDEO) { - if (info->biggest_tag_body_size < body_length) { - info->biggest_tag_body_size = body_length; - } - info->last_timestamp = timestamp; - } - - if (ft.type == FLV_TAG_TYPE_META) { - amf_data *tag_name, *data; - int retval; - tag_name = data = NULL; - - if (body_length == 0) { - } else { - retval = flv_read_metadata(flv_in, &tag_name, &data); - if (retval == FLV_ERROR_EOF) { - amf_data_free(tag_name); - amf_data_free(data); - return FLV_ERROR_EOF; - } else if (retval == FLV_ERROR_INVALID_METADATA_NAME) { - } else if (retval == FLV_ERROR_INVALID_METADATA) { - } - } - - /* check metadata name */ - if (body_length > 0 && amf_data_get_type(tag_name) == AMF_TYPE_STRING) { - char * name = (char *)amf_string_get_bytes(tag_name); - size_t len = (size_t)amf_string_get_size(tag_name); - - /* get info only on the first onMetaData we read */ - if (info->on_metadata_size == 0 && !strncmp(name, "onMetaData", len)) { - info->on_metadata_size = body_length + FLV_TAG_SIZE + sizeof(uint32_be); - info->on_metadata_offset = offset; - - amf_data_free(data); - } - else { - if (!strncmp(name, "onLastSecond", len)) { - info->have_on_last_second = 1; - } - info->meta_data_size += (body_length + FLV_TAG_SIZE); - info->total_prev_tags_size += sizeof(uint32_be); - if (data != NULL) { - amf_data_free(data); - } - } - } - /* just ignore metadata that don't have a proper name */ - else { - info->meta_data_size += (body_length + FLV_TAG_SIZE); - info->total_prev_tags_size += sizeof(uint32_be); - amf_data_free(data); - } - amf_data_free(tag_name); - } - else if (ft.type == FLV_TAG_TYPE_VIDEO) { - flv_video_tag vt; - - /* do not take video frame into account if body length is zero and we ignore errors */ - if (body_length == 0) { - } else { - if (flv_read_video_tag(flv_in, &vt) != FLV_OK) { - return FLV_ERROR_EOF; - } - - if (info->have_video != 1) { - info->have_video = 1; - info->video_codec = flv_video_tag_codec_id(vt); - info->video_first_timestamp = timestamp; - } - - if (have_video_size != 1 - && flv_video_tag_frame_type(vt) == FLV_VIDEO_TAG_FRAME_TYPE_KEYFRAME) { - /* read first video frame to get critical info */ - result = compute_video_size(flv_in, info, body_length - sizeof(flv_video_tag)); - if (result != FLV_OK) { - return result; - } - - if (info->video_width > 0 && info->video_height > 0) { - have_video_size = 1; - } - /* if we cannot fetch that information from the first tag, we'll try - for each following video key frame */ - } - - /* add keyframe to list */ - if (flv_video_tag_frame_type(vt) == FLV_VIDEO_TAG_FRAME_TYPE_KEYFRAME) { - /* do not add keyframe if the previous one has the same timestamp */ - if (!info->have_keyframes - || (info->have_keyframes && info->last_keyframe_timestamp != timestamp)) { - info->have_keyframes = 1; - info->last_keyframe_timestamp = timestamp; - amf_array_push(info->times, amf_number_new(timestamp / 1000.0)); - amf_array_push(info->filepositions, amf_number_new((number64)offset)); - } - /* is last frame a key frame ? if so, we can seek to end */ - info->can_seek_to_end = 1; - } - else { - info->can_seek_to_end = 0; - } - - info->real_video_data_size += (body_length - 1); - } - - info->video_frames_number++; - - /* - we assume all video frames have the same size as the first one: - probably bogus but only used in case there's no audio in the file - */ - if (info->video_frame_duration == 0) { - info->video_frame_duration = timestamp - info->video_first_timestamp; - } - - info->video_data_size += (body_length + FLV_TAG_SIZE); - info->total_prev_tags_size += sizeof(uint32_be); - } - else if (ft.type == FLV_TAG_TYPE_AUDIO) { - flv_audio_tag at; - - /* do not take audio frame into account if body length is zero and we ignore errors */ - if (body_length == 0) { - } else { - if (flv_read_audio_tag(flv_in, &at) != FLV_OK) { - return FLV_ERROR_EOF; - } - - if (info->have_audio != 1) { - info->have_audio = 1; - info->audio_codec = flv_audio_tag_sound_format(at); - info->audio_rate = flv_audio_tag_sound_rate(at); - info->audio_size = flv_audio_tag_sound_size(at); - info->audio_stereo = flv_audio_tag_sound_type(at); - info->audio_first_timestamp = timestamp; - } - /* we assume all audio frames have the same size as the first one */ - if (info->audio_frame_duration == 0) { - info->audio_frame_duration = timestamp - info->audio_first_timestamp; - } - - info->real_audio_data_size += (body_length - 1); - } - - info->audio_data_size += (body_length + FLV_TAG_SIZE); - info->total_prev_tags_size += sizeof(uint32_be); - } - else { - return 7; - } - ++tag_number; - } - - return FLV_OK; -} - -/* - compute the metadata -*/ -void compute_metadata(flv_info * info, flv_metadata * meta) { - uint32 new_on_metadata_size, on_last_second_size; - file_offset_t data_size, total_filesize; - number64 duration, video_data_rate, framerate; - amf_data * amf_total_filesize; - amf_data * amf_total_data_size; - amf_node * node_t; - amf_node * node_f; - - meta->on_last_second_name = amf_str("onLastSecond"); - meta->on_last_second = amf_associative_array_new(); - meta->on_metadata_name = amf_str("onMetaData"); - meta->on_metadata = amf_associative_array_new(); - - amf_associative_array_add(meta->on_metadata, "hasMetadata", amf_boolean_new(1)); - amf_associative_array_add(meta->on_metadata, "hasVideo", amf_boolean_new(info->have_video)); - amf_associative_array_add(meta->on_metadata, "hasAudio", amf_boolean_new(info->have_audio)); - - if (info->have_audio) { - duration = (info->last_timestamp - info->first_timestamp + info->audio_frame_duration) / 1000.0; - } - else { - duration = (info->last_timestamp - info->first_timestamp + info->video_frame_duration) / 1000.0; - } - amf_associative_array_add(meta->on_metadata, "duration", amf_number_new(duration)); - - amf_associative_array_add(meta->on_metadata, "lasttimestamp", amf_number_new(info->last_timestamp / 1000.0)); - amf_associative_array_add(meta->on_metadata, "lastkeyframetimestamp", amf_number_new(info->last_keyframe_timestamp / 1000.0)); - - if (info->video_width > 0) - amf_associative_array_add(meta->on_metadata, "width", amf_number_new(info->video_width)); - if (info->video_height > 0) - amf_associative_array_add(meta->on_metadata, "height", amf_number_new(info->video_height)); - - video_data_rate = ((info->real_video_data_size / 1024.0) * 8.0) / duration; - amf_associative_array_add(meta->on_metadata, "videodatarate", amf_number_new(video_data_rate)); - - framerate = info->video_frames_number / duration; - amf_associative_array_add(meta->on_metadata, "framerate", amf_number_new(framerate)); - - if (info->have_audio) { - number64 audio_khz, audio_sample_rate; - number64 audio_data_rate = ((info->real_audio_data_size / 1024.0) * 8.0) / duration; - amf_associative_array_add(meta->on_metadata, "audiodatarate", amf_number_new(audio_data_rate)); - - audio_khz = 0.0; - switch (info->audio_rate) { - case FLV_AUDIO_TAG_SOUND_RATE_5_5: audio_khz = 5500.0; break; - case FLV_AUDIO_TAG_SOUND_RATE_11: audio_khz = 11000.0; break; - case FLV_AUDIO_TAG_SOUND_RATE_22: audio_khz = 22050.0; break; - case FLV_AUDIO_TAG_SOUND_RATE_44: audio_khz = 44100.0; break; - } - amf_associative_array_add(meta->on_metadata, "audiosamplerate", amf_number_new(audio_khz)); - audio_sample_rate = 0.0; - switch (info->audio_size) { - case FLV_AUDIO_TAG_SOUND_SIZE_8: audio_sample_rate = 8.0; break; - case FLV_AUDIO_TAG_SOUND_SIZE_16: audio_sample_rate = 16.0; break; - } - amf_associative_array_add(meta->on_metadata, "audiosamplesize", amf_number_new(audio_sample_rate)); - amf_associative_array_add(meta->on_metadata, "stereo", amf_boolean_new(info->audio_stereo == FLV_AUDIO_TAG_SOUND_TYPE_STEREO)); - } - - /* to be computed later */ - amf_total_filesize = amf_number_new(0); - amf_associative_array_add(meta->on_metadata, "filesize", amf_total_filesize); - - if (info->have_video) { - amf_associative_array_add(meta->on_metadata, "videosize", amf_number_new((number64)info->video_data_size)); - } - if (info->have_audio) { - amf_associative_array_add(meta->on_metadata, "audiosize", amf_number_new((number64)info->audio_data_size)); - } - - /* to be computed later */ - amf_total_data_size = amf_number_new(0); - amf_associative_array_add(meta->on_metadata, "datasize", amf_total_data_size); - - amf_associative_array_add(meta->on_metadata, "metadatacreator", amf_str("xingmeng")); - - amf_associative_array_add(meta->on_metadata, "metadatadate", amf_date_new((number64)time(NULL)*1000, 0)); - if (info->have_audio) { - amf_associative_array_add(meta->on_metadata, "audiocodecid", amf_number_new((number64)info->audio_codec)); - } - if (info->have_video) { - amf_associative_array_add(meta->on_metadata, "videocodecid", amf_number_new((number64)info->video_codec)); - } - if (info->have_audio && info->have_video) { - number64 audio_delay = ((sint32)info->audio_first_timestamp - (sint32)info->video_first_timestamp) / 1000.0; - amf_associative_array_add(meta->on_metadata, "audiodelay", amf_number_new((number64)audio_delay)); - } - amf_associative_array_add(meta->on_metadata, "canSeekToEnd", amf_boolean_new(info->can_seek_to_end)); - - /* only add empty cuepoints if we don't preserve existing tags OR if the existing tags don't have cuepoints */ - if ((amf_associative_array_get(info->original_on_metadata, "cuePoints") == NULL)) { - amf_associative_array_add(meta->on_metadata, "hasCuePoints", amf_boolean_new(0)); - amf_associative_array_add(meta->on_metadata, "cuePoints", amf_array_new()); - } - amf_associative_array_add(meta->on_metadata, "hasKeyframes", amf_boolean_new(info->have_keyframes)); - amf_associative_array_add(meta->on_metadata, "keyframes", info->keyframes); - - /* - When we know the final size, we can recompute te offsets for the filepositions, and the final datasize. - */ - new_on_metadata_size = FLV_TAG_SIZE + sizeof(uint32_be) + - (uint32)(amf_data_size(meta->on_metadata_name) + amf_data_size(meta->on_metadata)); - on_last_second_size = (uint32)(amf_data_size(meta->on_last_second_name) + amf_data_size(meta->on_last_second)); - - node_t = amf_array_first(info->times); - node_f = amf_array_first(info->filepositions); - while (node_t != NULL || node_f != NULL) { - amf_data * amf_filepos = amf_array_get(node_f); - number64 offset = amf_number_get_value(amf_filepos) + new_on_metadata_size - info->on_metadata_size; - number64 timestamp = amf_number_get_value(amf_array_get(node_t)); - - /* after the onLastSecond event we need to take in account the tag size */ - if (!info->have_on_last_second && (info->last_timestamp - timestamp * 1000) <= 1000) { - offset += (FLV_TAG_SIZE + on_last_second_size + sizeof(uint32_be)); - } - - amf_number_set_value(amf_filepos, offset); - node_t = amf_array_next(node_t); - node_f = amf_array_next(node_f); - } - - /* compute data size, ie. size of metadata excluding prev_tag_size */ - data_size = info->meta_data_size + FLV_TAG_SIZE + - (uint32)(amf_data_size(meta->on_metadata_name) + amf_data_size(meta->on_metadata)); - if (!info->have_on_last_second) { - data_size += (uint32)on_last_second_size + FLV_TAG_SIZE; - } - amf_number_set_value(amf_total_data_size, (number64)data_size); - - /* compute total file size */ - total_filesize = FLV_HEADER_SIZE + info->total_prev_tags_size + info->video_data_size + - info->audio_data_size + info->meta_data_size + new_on_metadata_size; - - if (!info->have_on_last_second) { - /* if we have to add onLastSecond, we must count the header and new prevTagSize we add */ - total_filesize += (uint32)(FLV_TAG_SIZE + on_last_second_size + sizeof(uint32_be)); - } - - amf_number_set_value(amf_total_filesize, (number64)total_filesize); -} - - diff --git a/LFLiveKit/packet/flv/info.h b/LFLiveKit/packet/flv/info.h deleted file mode 100755 index 5be20c0b..00000000 --- a/LFLiveKit/packet/flv/info.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - $Id: info.h 231 2011-06-27 13:46:19Z marc.noirot $ - - FLV Metadata updater - - Copyright (C) 2007-2012 Marc Noirot - - This file is part of FLVMeta. - - FLVMeta is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - FLVMeta 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 General Public License - along with FLVMeta; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#ifndef __INFO_H__ -#define __INFO_H__ -#include "flv.h" - -typedef struct __flv_info { - flv_header header; - uint8 have_video; - uint8 have_audio; - uint32 video_width; - uint32 video_height; - uint8 video_codec; - uint32 video_frames_number; - uint8 audio_codec; - uint8 audio_size; - uint8 audio_rate; - uint8 audio_stereo; - file_offset_t video_data_size; - file_offset_t audio_data_size; - file_offset_t meta_data_size; - file_offset_t real_video_data_size; - file_offset_t real_audio_data_size; - uint32 video_first_timestamp; - uint32 audio_first_timestamp; - uint32 first_timestamp; - uint8 can_seek_to_end; - uint8 have_keyframes; - uint32 last_keyframe_timestamp; - uint32 on_metadata_size; - file_offset_t on_metadata_offset; - uint32 biggest_tag_body_size; - uint32 last_timestamp; - uint32 video_frame_duration; - uint32 audio_frame_duration; - file_offset_t total_prev_tags_size; - uint8 have_on_last_second; - amf_data * original_on_metadata; - amf_data * keyframes; - amf_data * times; - amf_data * filepositions; -} flv_info; - -typedef struct __flv_metadata { - amf_data * on_last_second_name; - amf_data * on_last_second; - amf_data * on_metadata_name; - amf_data * on_metadata; -} flv_metadata; - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -int get_flv_info(flv_stream * flv_in, flv_info * info); - -void compute_metadata(flv_info * info, flv_metadata * meta); - -void compute_current_metadata(flv_info * info, flv_metadata * meta); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __INFO_H__ */ diff --git a/LFLiveKit/packet/flv/types.c b/LFLiveKit/packet/flv/types.c deleted file mode 100755 index d417299b..00000000 --- a/LFLiveKit/packet/flv/types.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - $Id: types.c 231 2011-06-27 13:46:19Z marc.noirot $ - - FLV Metadata updater - - Copyright (C) 2007-2012 Marc Noirot - - This file is part of FLVMeta. - - FLVMeta is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - FLVMeta 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 General Public License - along with FLVMeta; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#include "types.h" - -#ifndef WORDS_BIGENDIAN - -/* swap 64 bits doubles */ -typedef union __convert_u { - uint64 i; - number64 f; -} convert_u; - -number64 swap_number64(number64 n) { - convert_u c; - c.f = n; - c.i = (((c.i & 0x00000000000000FFULL) << 56) | - ((c.i & 0x000000000000FF00ULL) << 40) | - ((c.i & 0x0000000000FF0000ULL) << 24) | - ((c.i & 0x00000000FF000000ULL) << 8) | - ((c.i & 0x000000FF00000000ULL) >> 8) | - ((c.i & 0x0000FF0000000000ULL) >> 24) | - ((c.i & 0x00FF000000000000ULL) >> 40) | - ((c.i & 0xFF00000000000000ULL) >> 56)); - return c.f; -} -#endif /* !defined WORDS_BIGENDIAN */ - -/* convert native integers into 24 bits big endian integers */ -uint24_be uint32_to_uint24_be(uint32 l) { - uint24_be r; - r.b[0] = (uint8)((l & 0x00FF0000U) >> 16); - r.b[1] = (uint8)((l & 0x0000FF00U) >> 8); - r.b[2] = (uint8) (l & 0x000000FFU); - return r; -} - -#ifdef WIN32 - -/* - These functions assume fpos_t is a 64-bit signed integer -*/ - -file_offset_t lfs_ftell(FILE * stream) { - fpos_t p; - if (fgetpos(stream, &p) == 0) { - return (file_offset_t)p; - } - else { - return -1LL; - } -} - -int lfs_fseek(FILE * stream, file_offset_t offset, int whence) { - fpos_t p; - if (fgetpos(stream, &p) == 0) { - switch (whence) { - case SEEK_CUR: p += offset; break; - case SEEK_SET: p = offset; break; - /*case SEEK_END:; not implemented here */ - default: - return -1; - } - fsetpos(stream, &p); - return 0; - } - else { - return -1; - } -} - -#endif /* WIN32 */ diff --git a/LFLiveKit/packet/flv/types.h b/LFLiveKit/packet/flv/types.h deleted file mode 100755 index 496e35b2..00000000 --- a/LFLiveKit/packet/flv/types.h +++ /dev/null @@ -1,141 +0,0 @@ -/* - $Id: types.h 231 2011-06-27 13:46:19Z marc.noirot $ - - FLV Metadata updater - - Copyright (C) 2007-2012 Marc Noirot - - This file is part of FLVMeta. - - FLVMeta is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - FLVMeta 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 General Public License - along with FLVMeta; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#ifndef __TYPES_H__ -#define __TYPES_H__ - -#include - -#include - -typedef uint8_t byte, uint8, uint8_bitmask; - -typedef uint16_t uint16, uint16_be, uint16_le; - -typedef int16_t sint16, sint16_be, sint16_le; - -typedef uint32_t uint32, uint32_be, uint32_le; - -typedef int32_t sint32, sint32_be, sint32_le; - -typedef struct __uint24 { - uint8 b[3]; -} uint24, uint24_be, uint24_le; - -typedef uint64_t uint64, uint64_le, uint64_be; - -typedef int64_t sint64, sint64_le, sint64_be; - -//typedef -//#if SIZEOF_FLOAT == 8 -//float -//#elif SIZEOF_DOUBLE == 8 -//double -//#elif SIZEOF_LONG_DOUBLE == 8 -//long double -//#else -//uint64_t -//#endif -//number64, number64_le, number64_be; - -typedef double number64, number64_le, number64_be; - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifdef WORDS_BIGENDIAN - -# define swap_uint16(x) (x) -# define swap_sint16(x) (x) -# define swap_uint32(x) (x) -# define swap_number64(x) (x) - -#else /* !defined WORDS_BIGENDIAN */ - -/* swap 16 bits integers */ -# define swap_uint16(x) ((uint16)((((x) & 0x00FFU) << 8) | \ - (((x) & 0xFF00U) >> 8))) -# define swap_sint16(x) ((sint16)((((x) & 0x00FF) << 8) | \ - (((x) & 0xFF00) >> 8))) - -/* swap 32 bits integers */ -# define swap_uint32(x) ((uint32)((((x) & 0x000000FFU) << 24) | \ - (((x) & 0x0000FF00U) << 8) | \ - (((x) & 0x00FF0000U) >> 8) | \ - (((x) & 0xFF000000U) >> 24))) - -/* swap 64 bits doubles */ -number64 swap_number64(number64); - -#endif /* WORDS_BIGENDIAN */ - -/* convert big endian 24 bits integers to native integers */ -# define uint24_be_to_uint32(x) ((uint32)(((x).b[0] << 16) | \ - ((x).b[1] << 8) | (x).b[2])) - -/* convert native integers into 24 bits big endian integers */ -uint24_be uint32_to_uint24_be(uint32); - -/* large file support */ -#ifdef HAVE_FSEEKO -# define lfs_ftell ftello -# define lfs_fseek fseeko - -# define FILE_OFFSET_T_64_BITS 1 -typedef off_t file_offset_t; - -#else /* !HAVE_SEEKO */ - -# ifdef WIN32 - -# define FILE_OFFSET_T_64_BITS 1 -typedef long long int file_offset_t; - -/* Win32 large file support */ -file_offset_t lfs_ftell(FILE * stream); -int lfs_fseek(FILE * stream, file_offset_t offset, int whence); - -# else /* !defined WIN32 */ - -# define lfs_ftell ftell -# define lfs_fseek fseek - -typedef long file_offset_t; - -# endif /* WIN32 */ - -#endif /* HAVE_FSEEKO */ - -/* file offset printf specifier */ -#ifdef FILE_OFFSET_T_64_BITS -# define FILE_OFFSET_PRINTF_FORMAT "ll" -#else -# define FILE_OFFSET_PRINTF_FORMAT "l" -#endif - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __TYPES_H__ */ diff --git a/LFLiveKit/upload/LFStreamRtmpSocket.h b/LFLiveKit/publish/LFStreamRTMPSocket.h similarity index 67% rename from LFLiveKit/upload/LFStreamRtmpSocket.h rename to LFLiveKit/publish/LFStreamRTMPSocket.h index c7a868a3..c613ff9f 100644 --- a/LFLiveKit/upload/LFStreamRtmpSocket.h +++ b/LFLiveKit/publish/LFStreamRTMPSocket.h @@ -1,14 +1,14 @@ // -// LFStreamRtmpSocket.h +// LFStreamRTMPSocket.h // LaiFeng // -// Created by admin on 16/5/18. -// Copyright © 2016年 live Interactive. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFStreamSocket.h" -@interface LFStreamRtmpSocket : NSObject +@interface LFStreamRTMPSocket : NSObject #pragma mark - Initializer ///============================================================================= diff --git a/LFLiveKit/publish/LFStreamRtmpSocket.m b/LFLiveKit/publish/LFStreamRtmpSocket.m new file mode 100644 index 00000000..89118046 --- /dev/null +++ b/LFLiveKit/publish/LFStreamRtmpSocket.m @@ -0,0 +1,585 @@ +// +// LFStreamRTMPSocket.m +// LFLiveKit +// +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. +// + +#import "LFStreamRTMPSocket.h" + +#if __has_include() +#import +#else +#import "rtmp.h" +#endif + +static const NSInteger RetryTimesBreaken = 5; ///< 重连1分钟 3秒一次 一共20次 +static const NSInteger RetryTimesMargin = 3; + + +#define RTMP_RECEIVE_TIMEOUT 2 +#define DATA_ITEMS_MAX_COUNT 100 +#define RTMP_DATA_RESERVE_SIZE 400 +#define RTMP_HEAD_SIZE (sizeof(RTMPPacket) + RTMP_MAX_HEADER_SIZE) + +#define SAVC(x) static const AVal av_ ## x = AVC(#x) + +static const AVal av_setDataFrame = AVC("@setDataFrame"); +static const AVal av_SDKVersion = AVC("LFLiveKit 2.4.0"); +SAVC(onMetaData); +SAVC(duration); +SAVC(width); +SAVC(height); +SAVC(videocodecid); +SAVC(videodatarate); +SAVC(framerate); +SAVC(audiocodecid); +SAVC(audiodatarate); +SAVC(audiosamplerate); +SAVC(audiosamplesize); +//SAVC(audiochannels); +SAVC(stereo); +SAVC(encoder); +//SAVC(av_stereo); +SAVC(fileSize); +SAVC(avc1); +SAVC(mp4a); + +@interface LFStreamRTMPSocket () +{ + PILI_RTMP *_rtmp; +} +@property (nonatomic, weak) id delegate; +@property (nonatomic, strong) LFLiveStreamInfo *stream; +@property (nonatomic, strong) LFStreamingBuffer *buffer; +@property (nonatomic, strong) LFLiveDebug *debugInfo; +@property (nonatomic, strong) dispatch_queue_t rtmpSendQueue; +//错误信息 +@property (nonatomic, assign) RTMPError error; +@property (nonatomic, assign) NSInteger retryTimes4netWorkBreaken; +@property (nonatomic, assign) NSInteger reconnectInterval; +@property (nonatomic, assign) NSInteger reconnectCount; + +@property (atomic, assign) BOOL isSending; +@property (nonatomic, assign) BOOL isConnected; +@property (nonatomic, assign) BOOL isConnecting; +@property (nonatomic, assign) BOOL isReconnecting; + +@property (nonatomic, assign) BOOL sendVideoHead; +@property (nonatomic, assign) BOOL sendAudioHead; + +@end + +@implementation LFStreamRTMPSocket + +#pragma mark -- LFStreamSocket +- (nullable instancetype)initWithStream:(nullable LFLiveStreamInfo *)stream{ + return [self initWithStream:stream reconnectInterval:0 reconnectCount:0]; +} + +- (nullable instancetype)initWithStream:(nullable LFLiveStreamInfo *)stream reconnectInterval:(NSInteger)reconnectInterval reconnectCount:(NSInteger)reconnectCount{ + if (!stream) @throw [NSException exceptionWithName:@"LFStreamRtmpSocket init error" reason:@"stream is nil" userInfo:nil]; + if (self = [super init]) { + _stream = stream; + if (reconnectInterval > 0) _reconnectInterval = reconnectInterval; + else _reconnectInterval = RetryTimesMargin; + + if (reconnectCount > 0) _reconnectCount = reconnectCount; + else _reconnectCount = RetryTimesBreaken; + + [self addObserver:self forKeyPath:@"isSending" options:NSKeyValueObservingOptionNew context:nil];//这里改成observer主要考虑一直到发送出错情况下,可以继续发送 + } + return self; +} + +- (void)dealloc{ + [self removeObserver:self forKeyPath:@"isSending"]; +} + +- (void)start { + dispatch_async(self.rtmpSendQueue, ^{ + [self _start]; + }); +} + +- (void)_start { + if (!_stream) return; + if (_isConnecting) return; + if (_rtmp != NULL) return; + self.debugInfo.streamId = self.stream.streamId; + self.debugInfo.uploadUrl = self.stream.url; + self.debugInfo.isRtmp = YES; + if (_isConnecting) return; + + _isConnecting = YES; + if (self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]) { + [self.delegate socketStatus:self status:LFLivePending]; + } + + if (_rtmp != NULL) { + PILI_RTMP_Close(_rtmp, &_error); + PILI_RTMP_Free(_rtmp); + } + [self RTMP264_Connect:(char *)[_stream.url cStringUsingEncoding:NSASCIIStringEncoding]]; +} + +- (void)stop { + dispatch_async(self.rtmpSendQueue, ^{ + [self _stop]; + [NSObject cancelPreviousPerformRequestsWithTarget:self]; + }); +} + +- (void)_stop { + if (self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]) { + [self.delegate socketStatus:self status:LFLiveStop]; + } + if (_rtmp != NULL) { + PILI_RTMP_Close(_rtmp, &_error); + PILI_RTMP_Free(_rtmp); + _rtmp = NULL; + } + [self clean]; +} + +- (void)sendFrame:(LFFrame *)frame { + if (!frame) return; + [self.buffer appendObject:frame]; + + if(!self.isSending){ + [self sendFrame]; + } +} + +- (void)setDelegate:(id)delegate { + _delegate = delegate; +} + +#pragma mark -- CustomMethod +- (void)sendFrame { + __weak typeof(self) _self = self; + dispatch_async(self.rtmpSendQueue, ^{ + if (!_self.isSending && _self.buffer.list.count > 0) { + _self.isSending = YES; + + if (!_self.isConnected || _self.isReconnecting || _self.isConnecting || !_rtmp){ + _self.isSending = NO; + return; + } + + // 调用发送接口 + LFFrame *frame = [_self.buffer popFirstObject]; + if ([frame isKindOfClass:[LFVideoFrame class]]) { + if (!_self.sendVideoHead) { + _self.sendVideoHead = YES; + if(!((LFVideoFrame*)frame).sps || !((LFVideoFrame*)frame).pps){ + _self.isSending = NO; + return; + } + [_self sendVideoHeader:(LFVideoFrame *)frame]; + } else { + [_self sendVideo:(LFVideoFrame *)frame]; + } + } else { + if (!_self.sendAudioHead) { + _self.sendAudioHead = YES; + if(!((LFAudioFrame*)frame).audioInfo){ + _self.isSending = NO; + return; + } + [_self sendAudioHeader:(LFAudioFrame *)frame]; + } else { + [_self sendAudio:frame]; + } + } + + //debug更新 + _self.debugInfo.totalFrame++; + _self.debugInfo.dropFrame += _self.buffer.lastDropFrames; + _self.buffer.lastDropFrames = 0; + + _self.debugInfo.dataFlow += frame.data.length; + _self.debugInfo.elapsedMilli = CACurrentMediaTime() * 1000 - _self.debugInfo.timeStamp; + if (_self.debugInfo.elapsedMilli < 1000) { + _self.debugInfo.bandwidth += frame.data.length; + if ([frame isKindOfClass:[LFAudioFrame class]]) { + _self.debugInfo.capturedAudioCount++; + } else { + _self.debugInfo.capturedVideoCount++; + } + + _self.debugInfo.unSendCount = _self.buffer.list.count; + } else { + _self.debugInfo.currentBandwidth = _self.debugInfo.bandwidth; + _self.debugInfo.currentCapturedAudioCount = _self.debugInfo.capturedAudioCount; + _self.debugInfo.currentCapturedVideoCount = _self.debugInfo.capturedVideoCount; + if (_self.delegate && [_self.delegate respondsToSelector:@selector(socketDebug:debugInfo:)]) { + [_self.delegate socketDebug:_self debugInfo:_self.debugInfo]; + } + _self.debugInfo.bandwidth = 0; + _self.debugInfo.capturedAudioCount = 0; + _self.debugInfo.capturedVideoCount = 0; + _self.debugInfo.timeStamp = CACurrentMediaTime() * 1000; + } + + //修改发送状态 + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + //< 这里只为了不循环调用sendFrame方法 调用栈是保证先出栈再进栈 + _self.isSending = NO; + }); + + } + }); +} + +- (void)clean { + _isConnecting = NO; + _isReconnecting = NO; + _isSending = NO; + _isConnected = NO; + _sendAudioHead = NO; + _sendVideoHead = NO; + self.debugInfo = nil; + [self.buffer removeAllObject]; + self.retryTimes4netWorkBreaken = 0; +} + +- (NSInteger)RTMP264_Connect:(char *)push_url { + //由于摄像头的timestamp是一直在累加,需要每次得到相对时间戳 + //分配与初始化 + _rtmp = PILI_RTMP_Alloc(); + PILI_RTMP_Init(_rtmp); + + //设置URL + if (PILI_RTMP_SetupURL(_rtmp, push_url, &_error) == FALSE) { + //log(LOG_ERR, "RTMP_SetupURL() failed!"); + goto Failed; + } + + _rtmp->m_errorCallback = RTMPErrorCallback; + _rtmp->m_connCallback = ConnectionTimeCallback; + _rtmp->m_userData = (__bridge void *)self; + _rtmp->m_msgCounter = 1; + _rtmp->Link.timeout = RTMP_RECEIVE_TIMEOUT; + + //设置可写,即发布流,这个函数必须在连接前使用,否则无效 + PILI_RTMP_EnableWrite(_rtmp); + + //连接服务器 + if (PILI_RTMP_Connect(_rtmp, NULL, &_error) == FALSE) { + goto Failed; + } + + //连接流 + if (PILI_RTMP_ConnectStream(_rtmp, 0, &_error) == FALSE) { + goto Failed; + } + + if (self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]) { + [self.delegate socketStatus:self status:LFLiveStart]; + } + + [self sendMetaData]; + + _isConnected = YES; + _isConnecting = NO; + _isReconnecting = NO; + _isSending = NO; + return 0; + +Failed: + PILI_RTMP_Close(_rtmp, &_error); + PILI_RTMP_Free(_rtmp); + _rtmp = NULL; + [self reconnect]; + return -1; +} + +#pragma mark -- Rtmp Send + +- (void)sendMetaData { + PILI_RTMPPacket packet; + + char pbuf[2048], *pend = pbuf + sizeof(pbuf); + + packet.m_nChannel = 0x03; // control channel (invoke) + packet.m_headerType = RTMP_PACKET_SIZE_LARGE; + packet.m_packetType = RTMP_PACKET_TYPE_INFO; + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = _rtmp->m_stream_id; + packet.m_hasAbsTimestamp = TRUE; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + char *enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_setDataFrame); + enc = AMF_EncodeString(enc, pend, &av_onMetaData); + + *enc++ = AMF_OBJECT; + + enc = AMF_EncodeNamedNumber(enc, pend, &av_duration, 0.0); + enc = AMF_EncodeNamedNumber(enc, pend, &av_fileSize, 0.0); + + // videosize + enc = AMF_EncodeNamedNumber(enc, pend, &av_width, _stream.videoConfiguration.videoSize.width); + enc = AMF_EncodeNamedNumber(enc, pend, &av_height, _stream.videoConfiguration.videoSize.height); + + // video + enc = AMF_EncodeNamedString(enc, pend, &av_videocodecid, &av_avc1); + + enc = AMF_EncodeNamedNumber(enc, pend, &av_videodatarate, _stream.videoConfiguration.videoBitRate / 1000.f); + enc = AMF_EncodeNamedNumber(enc, pend, &av_framerate, _stream.videoConfiguration.videoFrameRate); + + // audio + enc = AMF_EncodeNamedString(enc, pend, &av_audiocodecid, &av_mp4a); + enc = AMF_EncodeNamedNumber(enc, pend, &av_audiodatarate, _stream.audioConfiguration.audioBitrate); + + enc = AMF_EncodeNamedNumber(enc, pend, &av_audiosamplerate, _stream.audioConfiguration.audioSampleRate); + enc = AMF_EncodeNamedNumber(enc, pend, &av_audiosamplesize, 16.0); + enc = AMF_EncodeNamedBoolean(enc, pend, &av_stereo, _stream.audioConfiguration.numberOfChannels == 2); + + // sdk version + enc = AMF_EncodeNamedString(enc, pend, &av_encoder, &av_SDKVersion); + + *enc++ = 0; + *enc++ = 0; + *enc++ = AMF_OBJECT_END; + + packet.m_nBodySize = (uint32_t)(enc - packet.m_body); + if (!PILI_RTMP_SendPacket(_rtmp, &packet, FALSE, &_error)) { + return; + } +} + +- (void)sendVideoHeader:(LFVideoFrame *)videoFrame { + + unsigned char *body = NULL; + NSInteger iIndex = 0; + NSInteger rtmpLength = 1024; + const char *sps = videoFrame.sps.bytes; + const char *pps = videoFrame.pps.bytes; + NSInteger sps_len = videoFrame.sps.length; + NSInteger pps_len = videoFrame.pps.length; + + body = (unsigned char *)malloc(rtmpLength); + memset(body, 0, rtmpLength); + + body[iIndex++] = 0x17; + body[iIndex++] = 0x00; + + body[iIndex++] = 0x00; + body[iIndex++] = 0x00; + body[iIndex++] = 0x00; + + body[iIndex++] = 0x01; + body[iIndex++] = sps[1]; + body[iIndex++] = sps[2]; + body[iIndex++] = sps[3]; + body[iIndex++] = 0xff; + + /*sps*/ + body[iIndex++] = 0xe1; + body[iIndex++] = (sps_len >> 8) & 0xff; + body[iIndex++] = sps_len & 0xff; + memcpy(&body[iIndex], sps, sps_len); + iIndex += sps_len; + + /*pps*/ + body[iIndex++] = 0x01; + body[iIndex++] = (pps_len >> 8) & 0xff; + body[iIndex++] = (pps_len) & 0xff; + memcpy(&body[iIndex], pps, pps_len); + iIndex += pps_len; + + [self sendPacket:RTMP_PACKET_TYPE_VIDEO data:body size:iIndex nTimestamp:0]; + free(body); +} + +- (void)sendVideo:(LFVideoFrame *)frame { + + NSInteger i = 0; + NSInteger rtmpLength = frame.data.length + 9; + unsigned char *body = (unsigned char *)malloc(rtmpLength); + memset(body, 0, rtmpLength); + + if (frame.isKeyFrame) { + body[i++] = 0x17; // 1:Iframe 7:AVC + } else { + body[i++] = 0x27; // 2:Pframe 7:AVC + } + body[i++] = 0x01; // AVC NALU + body[i++] = 0x00; + body[i++] = 0x00; + body[i++] = 0x00; + body[i++] = (frame.data.length >> 24) & 0xff; + body[i++] = (frame.data.length >> 16) & 0xff; + body[i++] = (frame.data.length >> 8) & 0xff; + body[i++] = (frame.data.length) & 0xff; + memcpy(&body[i], frame.data.bytes, frame.data.length); + + [self sendPacket:RTMP_PACKET_TYPE_VIDEO data:body size:(rtmpLength) nTimestamp:frame.timestamp]; + free(body); +} + +- (NSInteger)sendPacket:(unsigned int)nPacketType data:(unsigned char *)data size:(NSInteger)size nTimestamp:(uint64_t)nTimestamp { + NSInteger rtmpLength = size; + PILI_RTMPPacket rtmp_pack; + PILI_RTMPPacket_Reset(&rtmp_pack); + PILI_RTMPPacket_Alloc(&rtmp_pack, (uint32_t)rtmpLength); + + rtmp_pack.m_nBodySize = (uint32_t)size; + memcpy(rtmp_pack.m_body, data, size); + rtmp_pack.m_hasAbsTimestamp = 0; + rtmp_pack.m_packetType = nPacketType; + if (_rtmp) rtmp_pack.m_nInfoField2 = _rtmp->m_stream_id; + rtmp_pack.m_nChannel = 0x04; + rtmp_pack.m_headerType = RTMP_PACKET_SIZE_LARGE; + if (RTMP_PACKET_TYPE_AUDIO == nPacketType && size != 4) { + rtmp_pack.m_headerType = RTMP_PACKET_SIZE_MEDIUM; + } + rtmp_pack.m_nTimeStamp = (uint32_t)nTimestamp; + + NSInteger nRet = [self RtmpPacketSend:&rtmp_pack]; + + PILI_RTMPPacket_Free(&rtmp_pack); + return nRet; +} + +- (NSInteger)RtmpPacketSend:(PILI_RTMPPacket *)packet { + if (_rtmp && PILI_RTMP_IsConnected(_rtmp)) { + int success = PILI_RTMP_SendPacket(_rtmp, packet, 0, &_error); + return success; + } + return -1; +} + +- (void)sendAudioHeader:(LFAudioFrame *)audioFrame { + + NSInteger rtmpLength = audioFrame.audioInfo.length + 2; /*spec data长度,一般是2*/ + unsigned char *body = (unsigned char *)malloc(rtmpLength); + memset(body, 0, rtmpLength); + + /*AF 00 + AAC RAW data*/ + body[0] = 0xAF; + body[1] = 0x00; + memcpy(&body[2], audioFrame.audioInfo.bytes, audioFrame.audioInfo.length); /*spec_buf是AAC sequence header数据*/ + [self sendPacket:RTMP_PACKET_TYPE_AUDIO data:body size:rtmpLength nTimestamp:0]; + free(body); +} + +- (void)sendAudio:(LFFrame *)frame { + + NSInteger rtmpLength = frame.data.length + 2; /*spec data长度,一般是2*/ + unsigned char *body = (unsigned char *)malloc(rtmpLength); + memset(body, 0, rtmpLength); + + /*AF 01 + AAC RAW data*/ + body[0] = 0xAF; + body[1] = 0x01; + memcpy(&body[2], frame.data.bytes, frame.data.length); + [self sendPacket:RTMP_PACKET_TYPE_AUDIO data:body size:rtmpLength nTimestamp:frame.timestamp]; + free(body); +} + +// 断线重连 +- (void)reconnect { + dispatch_async(self.rtmpSendQueue, ^{ + if (self.retryTimes4netWorkBreaken++ < self.reconnectCount && !self.isReconnecting) { + self.isConnected = NO; + self.isConnecting = NO; + self.isReconnecting = YES; + dispatch_async(dispatch_get_main_queue(), ^{ + [self performSelector:@selector(_reconnect) withObject:nil afterDelay:self.reconnectInterval]; + }); + + } else if (self.retryTimes4netWorkBreaken >= self.reconnectCount) { + if (self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]) { + [self.delegate socketStatus:self status:LFLiveError]; + } + if (self.delegate && [self.delegate respondsToSelector:@selector(socketDidError:errorCode:)]) { + [self.delegate socketDidError:self errorCode:LFLiveSocketError_ReConnectTimeOut]; + } + } + }); +} + +- (void)_reconnect{ + [NSObject cancelPreviousPerformRequestsWithTarget:self]; + + _isReconnecting = NO; + if(_isConnected) return; + + _isReconnecting = NO; + if (_isConnected) return; + if (_rtmp != NULL) { + PILI_RTMP_Close(_rtmp, &_error); + PILI_RTMP_Free(_rtmp); + _rtmp = NULL; + } + _sendAudioHead = NO; + _sendVideoHead = NO; + + if (self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]) { + [self.delegate socketStatus:self status:LFLiveRefresh]; + } + + if (_rtmp != NULL) { + PILI_RTMP_Close(_rtmp, &_error); + PILI_RTMP_Free(_rtmp); + } + [self RTMP264_Connect:(char *)[_stream.url cStringUsingEncoding:NSASCIIStringEncoding]]; +} + +#pragma mark -- CallBack +void RTMPErrorCallback(RTMPError *error, void *userData) { + LFStreamRTMPSocket *socket = (__bridge LFStreamRTMPSocket *)userData; + if (error->code < 0) { + [socket reconnect]; + } +} + +void ConnectionTimeCallback(PILI_CONNECTION_TIME *conn_time, void *userData) { +} + +#pragma mark -- LFStreamingBufferDelegate +- (void)streamingBuffer:(nullable LFStreamingBuffer *)buffer bufferState:(LFLiveBuffferState)state{ + if(self.delegate && [self.delegate respondsToSelector:@selector(socketBufferStatus:status:)]){ + [self.delegate socketBufferStatus:self status:state]; + } +} + +#pragma mark -- Observer +-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ + if([keyPath isEqualToString:@"isSending"]){ + if(!self.isSending){ + [self sendFrame]; + } + } +} + +#pragma mark -- Getter Setter + +- (LFStreamingBuffer *)buffer { + if (!_buffer) { + _buffer = [[LFStreamingBuffer alloc] init]; + _buffer.delegate = self; + + } + return _buffer; +} + +- (LFLiveDebug *)debugInfo { + if (!_debugInfo) { + _debugInfo = [[LFLiveDebug alloc] init]; + } + return _debugInfo; +} + +- (dispatch_queue_t)rtmpSendQueue{ + if(!_rtmpSendQueue){ + _rtmpSendQueue = dispatch_queue_create("com.youku.LaiFeng.RtmpSendQueue", NULL); + } + return _rtmpSendQueue; +} + +@end diff --git a/LFLiveKit/publish/LFStreamSocket.h b/LFLiveKit/publish/LFStreamSocket.h new file mode 100644 index 00000000..fcf79ee8 --- /dev/null +++ b/LFLiveKit/publish/LFStreamSocket.h @@ -0,0 +1,38 @@ +// +// LFStreamSocket.h +// LFLiveKit +// +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. +// + +#import +#import "LFLiveStreamInfo.h" +#import "LFStreamingBuffer.h" +#import "LFLiveDebug.h" + + + +@protocol LFStreamSocket; +@protocol LFStreamSocketDelegate + +/** callback buffer current status (回调当前缓冲区情况,可实现相关切换帧率 码率等策略)*/ +- (void)socketBufferStatus:(nullable id )socket status:(LFLiveBuffferState)status; +/** callback socket current status (回调当前网络情况) */ +- (void)socketStatus:(nullable id )socket status:(LFLiveState)status; +/** callback socket errorcode */ +- (void)socketDidError:(nullable id )socket errorCode:(LFLiveSocketErrorCode)errorCode; +@optional +/** callback debugInfo */ +- (void)socketDebug:(nullable id )socket debugInfo:(nullable LFLiveDebug *)debugInfo; +@end + +@protocol LFStreamSocket +- (void)start; +- (void)stop; +- (void)sendFrame:(nullable LFFrame *)frame; +- (void)setDelegate:(nullable id )delegate; +@optional +- (nullable instancetype)initWithStream:(nullable LFLiveStreamInfo *)stream; +- (nullable instancetype)initWithStream:(nullable LFLiveStreamInfo *)stream reconnectInterval:(NSInteger)reconnectInterval reconnectCount:(NSInteger)reconnectCount; +@end diff --git a/LFLiveKit/upload/LFStreamingBuffer.h b/LFLiveKit/publish/LFStreamingBuffer.h similarity index 52% rename from LFLiveKit/upload/LFStreamingBuffer.h rename to LFLiveKit/publish/LFStreamingBuffer.h index 14e6eea5..aa868b93 100755 --- a/LFLiveKit/upload/LFStreamingBuffer.h +++ b/LFLiveKit/publish/LFStreamingBuffer.h @@ -2,19 +2,20 @@ // LFStreamingBuffer.h // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import #import "LFAudioFrame.h" #import "LFVideoFrame.h" + /** current buffer status */ -typedef NS_ENUM(NSUInteger, LFLiveBuffferState) { +typedef NS_ENUM (NSUInteger, LFLiveBuffferState) { LFLiveBuffferUnknown = 0, //< 未知 - LFLiveBuffferIncrease = 1, //< 缓冲区状态好可以增加码率 - LFLiveBuffferDecline = 2 //< 缓冲区状态差应该降低码率 + LFLiveBuffferIncrease = 1, //< 缓冲区状态差应该降低码率 + LFLiveBuffferDecline = 2 //< 缓冲区状态好应该提升码率 }; @class LFStreamingBuffer; @@ -22,25 +23,29 @@ typedef NS_ENUM(NSUInteger, LFLiveBuffferState) { @protocol LFStreamingBufferDelegate @optional /** 当前buffer变动(增加or减少) 根据buffer中的updateInterval时间回调*/ -- (void)streamingBuffer:(nullable LFStreamingBuffer * )buffer bufferState:(LFLiveBuffferState)state; +- (void)streamingBuffer:(nullable LFStreamingBuffer *)buffer bufferState:(LFLiveBuffferState)state; @end @interface LFStreamingBuffer : NSObject + /** The delegate of the buffer. buffer callback */ -@property (nullable,nonatomic, weak) id delegate; +@property (nullable, nonatomic, weak) id delegate; /** current frame buffer */ -@property (nonatomic, strong, readonly) NSMutableArray * _Nonnull list; +@property (nonatomic, strong, readonly) NSMutableArray *_Nonnull list; /** buffer count max size default 1000 */ @property (nonatomic, assign) NSUInteger maxCount; +/** count of drop frames in last time */ +@property (nonatomic, assign) NSInteger lastDropFrames; + /** add frame to buffer */ -- (void)appendObject:(nullable LFFrame*)frame; +- (void)appendObject:(nullable LFFrame *)frame; /** pop the first frome buffer */ -- (nullable LFFrame*)popFirstObject; +- (nullable LFFrame *)popFirstObject; /** remove all objects from Buffer */ - (void)removeAllObject; diff --git a/LFLiveKit/upload/LFStreamingBuffer.m b/LFLiveKit/publish/LFStreamingBuffer.m similarity index 62% rename from LFLiveKit/upload/LFStreamingBuffer.m rename to LFLiveKit/publish/LFStreamingBuffer.m index 0a9b60c0..1c6c5504 100755 --- a/LFLiveKit/upload/LFStreamingBuffer.m +++ b/LFLiveKit/publish/LFStreamingBuffer.m @@ -2,14 +2,14 @@ // LFStreamingBuffer.m // LFLiveKit // -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "LFStreamingBuffer.h" #import "NSMutableArray+LFAdd.h" -static const NSUInteger defaultSortBufferMaxCount = 10;///< 排序10个内 +static const NSUInteger defaultSortBufferMaxCount = 5;///< 排序10个内 static const NSUInteger defaultUpdateInterval = 1;///< 更新频率为1s static const NSUInteger defaultCallBackInterval = 5;///< 5s计时一次 static const NSUInteger defaultSendBufferMaxCount = 600;///< 最大缓冲区为600 @@ -18,8 +18,8 @@ @interface LFStreamingBuffer (){ dispatch_semaphore_t _lock; } -@property (nonatomic, strong) NSMutableArray *sortList; -@property (nonatomic, strong, readwrite) NSMutableArray *list; +@property (nonatomic, strong) NSMutableArray *sortList; +@property (nonatomic, strong, readwrite) NSMutableArray *list; @property (nonatomic, strong) NSMutableArray *thresholdList; /** 处理buffer缓冲区情况 */ @@ -32,70 +32,73 @@ @interface LFStreamingBuffer (){ @implementation LFStreamingBuffer -- (instancetype)init{ - if(self = [super init]){ +- (instancetype)init { + if (self = [super init]) { + _lock = dispatch_semaphore_create(1); self.updateInterval = defaultUpdateInterval; self.callBackInterval = defaultCallBackInterval; self.maxCount = defaultSendBufferMaxCount; + self.lastDropFrames = 0; + self.startTimer = NO; } return self; } -- (void)dealloc{ +- (void)dealloc { } #pragma mark -- Custom -- (void)appendObject:(LFFrame*)frame{ - if(!frame) return; - if(!_startTimer){ +- (void)appendObject:(LFFrame *)frame { + if (!frame) return; + if (!_startTimer) { _startTimer = YES; [self tick]; } - + dispatch_semaphore_wait(_lock, DISPATCH_TIME_FOREVER); - if(self.sortList.count < defaultSortBufferMaxCount){ + if (self.sortList.count < defaultSortBufferMaxCount) { [self.sortList addObject:frame]; - }else{ + } else { ///< 排序 [self.sortList addObject:frame]; - NSArray *sortedSendQuery = [self.sortList sortedArrayUsingFunction:frameDataCompare context:NULL]; - [self.sortList removeAllObjects]; - [self.sortList addObjectsFromArray:sortedSendQuery]; + [self.sortList sortUsingFunction:frameDataCompare context:nil]; /// 丢帧 [self removeExpireFrame]; /// 添加至缓冲区 LFFrame *firstFrame = [self.sortList lfPopFirstObject]; - - if(firstFrame) [self.list addObject:firstFrame]; + + if (firstFrame) [self.list addObject:firstFrame]; } dispatch_semaphore_signal(_lock); } -- (LFFrame*)popFirstObject{ +- (LFFrame *)popFirstObject { dispatch_semaphore_wait(_lock, DISPATCH_TIME_FOREVER); LFFrame *firstFrame = [self.list lfPopFirstObject]; dispatch_semaphore_signal(_lock); return firstFrame; } -- (void)removeAllObject{ +- (void)removeAllObject { dispatch_semaphore_wait(_lock, DISPATCH_TIME_FOREVER); [self.list removeAllObjects]; dispatch_semaphore_signal(_lock); } -- (void)removeExpireFrame{ - if(self.list.count < self.maxCount) return; - +- (void)removeExpireFrame { + if (self.list.count < self.maxCount) return; + NSArray *pFrames = [self expirePFrames];///< 第一个P到第一个I之间的p帧 - if(pFrames && pFrames.count > 0){ + self.lastDropFrames += [pFrames count]; + if (pFrames && pFrames.count > 0) { [self.list removeObjectsInArray:pFrames]; return; } NSArray *iFrames = [self expireIFrames];///<  删除一个I帧(但一个I帧可能对应多个nal) - if(iFrames){ + self.lastDropFrames += [iFrames count]; + if (iFrames && iFrames.count > 0) { [self.list removeObjectsInArray:iFrames]; return; } @@ -103,15 +106,15 @@ - (void)removeExpireFrame{ [self.list removeAllObjects]; } -- (NSArray*)expirePFrames{ +- (NSArray *)expirePFrames { NSMutableArray *pframes = [[NSMutableArray alloc] init]; - for(NSInteger index = 0;index < self.list.count;index++){ + for (NSInteger index = 0; index < self.list.count; index++) { LFFrame *frame = [self.list objectAtIndex:index]; - if([frame isKindOfClass:[LFVideoFrame class]]){ - LFVideoFrame *videoFrame = (LFVideoFrame*)frame; - if(videoFrame.isKeyFrame && pframes.count > 0){ + if ([frame isKindOfClass:[LFVideoFrame class]]) { + LFVideoFrame *videoFrame = (LFVideoFrame *)frame; + if (videoFrame.isKeyFrame && pframes.count > 0) { break; - }else if(!videoFrame.isKeyFrame){ + } else if (!videoFrame.isKeyFrame) { [pframes addObject:frame]; } } @@ -119,13 +122,13 @@ - (NSArray*)expirePFrames{ return pframes; } -- (NSArray*)expireIFrames{ +- (NSArray *)expireIFrames { NSMutableArray *iframes = [[NSMutableArray alloc] init]; uint64_t timeStamp = 0; - for(NSInteger index = 0;index < self.list.count;index++){ + for (NSInteger index = 0; index < self.list.count; index++) { LFFrame *frame = [self.list objectAtIndex:index]; - if([frame isKindOfClass:[LFVideoFrame class]] && ((LFVideoFrame*)frame).isKeyFrame){ - if(timeStamp != 0 && timeStamp != frame.timestamp) break; + if ([frame isKindOfClass:[LFVideoFrame class]] && ((LFVideoFrame *)frame).isKeyFrame) { + if (timeStamp != 0 && timeStamp != frame.timestamp) break; [iframes addObject:frame]; timeStamp = frame.timestamp; } @@ -134,35 +137,35 @@ - (NSArray*)expireIFrames{ } NSInteger frameDataCompare(id obj1, id obj2, void *context){ - LFFrame* frame1 = (LFFrame*) obj1; - LFFrame *frame2 = (LFFrame*) obj2; - + LFFrame *frame1 = (LFFrame *)obj1; + LFFrame *frame2 = (LFFrame *)obj2; + if (frame1.timestamp == frame2.timestamp) return NSOrderedSame; - else if(frame1.timestamp > frame2.timestamp) + else if (frame1.timestamp > frame2.timestamp) return NSOrderedDescending; return NSOrderedAscending; } -- (LFLiveBuffferState)currentBufferState{ +- (LFLiveBuffferState)currentBufferState { NSInteger currentCount = 0; NSInteger increaseCount = 0; NSInteger decreaseCount = 0; - - for(NSNumber *number in self.thresholdList){ - if(number.integerValue >= currentCount){ - increaseCount ++; - }else{ - decreaseCount ++; + + for (NSNumber *number in self.thresholdList) { + if (number.integerValue > currentCount) { + increaseCount++; + } else{ + decreaseCount++; } currentCount = [number integerValue]; } - - if(increaseCount >= self.callBackInterval){ + + if (increaseCount >= self.callBackInterval) { return LFLiveBuffferIncrease; } - - if(decreaseCount >= self.callBackInterval){ + + if (decreaseCount >= self.callBackInterval) { return LFLiveBuffferDecline; } @@ -170,55 +173,54 @@ - (LFLiveBuffferState)currentBufferState{ } #pragma mark -- Setter Getter -- (NSMutableArray*)list{ - if(!_list){ +- (NSMutableArray *)list { + if (!_list) { _list = [[NSMutableArray alloc] init]; } return _list; } -- (NSMutableArray*)sortList{ - if(!_sortList){ +- (NSMutableArray *)sortList { + if (!_sortList) { _sortList = [[NSMutableArray alloc] init]; } return _sortList; } -- (NSMutableArray*)thresholdList{ - if(!_thresholdList){ +- (NSMutableArray *)thresholdList { + if (!_thresholdList) { _thresholdList = [[NSMutableArray alloc] init]; } return _thresholdList; } - #pragma mark -- 采样 -- (void)tick{ +- (void)tick { /** 采样 3个阶段 如果网络都是好或者都是差给回调 */ _currentInterval += self.updateInterval; - + dispatch_semaphore_wait(_lock, DISPATCH_TIME_FOREVER); [self.thresholdList addObject:@(self.list.count)]; dispatch_semaphore_signal(_lock); - if(self.currentInterval >= self.callBackInterval){ + if (self.currentInterval >= self.callBackInterval) { LFLiveBuffferState state = [self currentBufferState]; - if(state == LFLiveBuffferIncrease){ - if(self.delegate && [self.delegate respondsToSelector:@selector(streamingBuffer:bufferState:)]){ + if (state == LFLiveBuffferIncrease) { + if (self.delegate && [self.delegate respondsToSelector:@selector(streamingBuffer:bufferState:)]) { [self.delegate streamingBuffer:self bufferState:LFLiveBuffferIncrease]; } - }else if(state == LFLiveBuffferDecline){ - if(self.delegate && [self.delegate respondsToSelector:@selector(streamingBuffer:bufferState:)]){ + } else if (state == LFLiveBuffferDecline) { + if (self.delegate && [self.delegate respondsToSelector:@selector(streamingBuffer:bufferState:)]) { [self.delegate streamingBuffer:self bufferState:LFLiveBuffferDecline]; } } - + self.currentInterval = 0; [self.thresholdList removeAllObjects]; } __weak typeof(self) _self = self; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.updateInterval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - __weak typeof(_self) self = _self; + __strong typeof(_self) self = _self; [self tick]; }); } diff --git a/LFLiveKit/publish/NSMutableArray+LFAdd.h b/LFLiveKit/publish/NSMutableArray+LFAdd.h new file mode 100755 index 00000000..2b5673d0 --- /dev/null +++ b/LFLiveKit/publish/NSMutableArray+LFAdd.h @@ -0,0 +1,21 @@ +// +// NSMutableArray+LFAdd.h +// YYKit +// +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. +// + +#import + +@interface NSMutableArray (YYAdd) + +/** + Removes and returns the object with the lowest-valued index in the array. + If the array is empty, it just returns nil. + + @return The first object, or nil. + */ +- (nullable id)lfPopFirstObject; + +@end diff --git a/LFLiveKit/upload/NSMutableArray+LFAdd.m b/LFLiveKit/publish/NSMutableArray+LFAdd.m similarity index 81% rename from LFLiveKit/upload/NSMutableArray+LFAdd.m rename to LFLiveKit/publish/NSMutableArray+LFAdd.m index 48746e03..57d865f1 100755 --- a/LFLiveKit/upload/NSMutableArray+LFAdd.m +++ b/LFLiveKit/publish/NSMutableArray+LFAdd.m @@ -2,8 +2,8 @@ // NSMutableArray+LFAdd.m // YYKit // -// Created by admin on 16/5/20. -// Copyright © 2016年 倾慕. All rights reserved. +// Created by LaiFeng on 16/5/20. +// Copyright © 2016年 LaiFeng All rights reserved. // #import "NSMutableArray+LFAdd.h" diff --git a/LFLiveKit/upload/LFStreamRtmpSocket.m b/LFLiveKit/upload/LFStreamRtmpSocket.m deleted file mode 100644 index f7706abd..00000000 --- a/LFLiveKit/upload/LFStreamRtmpSocket.m +++ /dev/null @@ -1,505 +0,0 @@ -// -// LFStreamRtmpSocket.m -// LFLiveKit -// -// Created by admin on 16/5/18. -// Copyright © 2016年 live Interactive. All rights reserved. -// - -#import "LFStreamRtmpSocket.h" -#import "rtmp.h" - -static const NSInteger RetryTimesBreaken = 20;///< 重连1分钟 3秒一次 一共20次 -static const NSInteger RetryTimesMargin = 3; - -#define DATA_ITEMS_MAX_COUNT 100 -#define RTMP_DATA_RESERVE_SIZE 400 -#define RTMP_HEAD_SIZE (sizeof(RTMPPacket)+RTMP_MAX_HEADER_SIZE) - -#define SAVC(x) static const AVal av_##x = AVC(#x) - -static const AVal av_setDataFrame = AVC("@setDataFrame"); -static const AVal av_SDKVersion = AVC("LFLiveKit 1.6"); -SAVC(onMetaData); -SAVC(duration); -SAVC(width); -SAVC(height); -SAVC(videocodecid); -SAVC(videodatarate); -SAVC(framerate); -SAVC(audiocodecid); -SAVC(audiodatarate); -SAVC(audiosamplerate); -SAVC(audiosamplesize); -SAVC(audiochannels); -SAVC(stereo); -SAVC(encoder); -SAVC(av_stereo); -SAVC(fileSize); -SAVC(avc1); -SAVC(mp4a); - -@interface LFStreamRtmpSocket () -{ - PILI_RTMP* _rtmp; -} -@property (nonatomic, weak) id delegate; -@property (nonatomic, strong) LFLiveStreamInfo *stream; -@property (nonatomic, strong) LFStreamingBuffer *buffer; -@property (nonatomic, strong) dispatch_queue_t socketQueue; -@property (nonatomic, strong) LFLiveDebug *debugInfo; -//错误信息 -@property (nonatomic, assign) RTMPError error; -@property (nonatomic, assign) NSInteger retryTimes4netWorkBreaken; -@property (nonatomic, assign) NSInteger reconnectInterval; -@property (nonatomic, assign) NSInteger reconnectCount; - -@property (nonatomic, assign) BOOL isSending; -@property (nonatomic, assign) BOOL isConnected; -@property (nonatomic, assign) BOOL isConnecting; -@property (nonatomic, assign) BOOL isReconnecting; - -@property (nonatomic, assign) BOOL sendVideoHead; -@property (nonatomic, assign) BOOL sendAudioHead; - - - -@end - -@implementation LFStreamRtmpSocket - -#pragma mark -- LFStreamSocket -- (nullable instancetype)initWithStream:(nullable LFLiveStreamInfo*)stream videoSize:(CGSize)videoSize reconnectInterval:(NSInteger)reconnectInterval reconnectCount:(NSInteger)reconnectCount{ - if(!stream) @throw [NSException exceptionWithName:@"LFStreamRtmpSocket init error" reason:@"stream is nil" userInfo:nil]; - if(self = [super init]){ - _stream = stream; - if(reconnectInterval > 0) _reconnectInterval = reconnectInterval; - else _reconnectInterval = RetryTimesMargin; - - if(reconnectCount > 0) _reconnectCount = reconnectCount; - else _reconnectCount = RetryTimesBreaken; - } - return self; -} - -- (void) start{ - dispatch_async(self.socketQueue, ^{ - if(!_stream) return; - if(_isConnecting) return; - if(_rtmp != NULL) return; - self.debugInfo.streamId = self.stream.streamId; - self.debugInfo.uploadUrl = self.stream.url; - self.debugInfo.isRtmp = YES; - [self clean]; - [self RTMP264_Connect:(char*)[_stream.url cStringUsingEncoding:NSASCIIStringEncoding]]; - }); -} - -- (void) stop{ - dispatch_async(self.socketQueue, ^{ - if(_rtmp != NULL){ - PILI_RTMP_Close(_rtmp, &_error); - PILI_RTMP_Free(_rtmp); - _rtmp = NULL; - } - }); -} - -- (void) sendFrame:(LFFrame*)frame{ - __weak typeof(self) _self = self; - dispatch_async(self.socketQueue, ^{ - __strong typeof(_self) self = _self; - if(!frame) return; - [self.buffer appendObject:frame]; - [self sendFrame]; - }); -} - -- (void) setDelegate:(id)delegate{ - _delegate = delegate; -} - -#pragma mark -- CustomMethod -- (void)sendFrame{ - if(!self.isSending && self.buffer.list.count > 0){ - self.isSending = YES; - - if(!_isConnected || _isReconnecting || _isConnecting || !_rtmp) return; - - // 调用发送接口 - LFFrame *frame = [self.buffer popFirstObject]; - if([frame isKindOfClass:[LFVideoFrame class]]){ - if(!self.sendVideoHead){ - self.sendVideoHead = YES; - [self sendVideoHeader:(LFVideoFrame*)frame]; - }else{ - [self sendVideo:(LFVideoFrame*)frame]; - } - }else{ - if(!self.sendAudioHead){ - self.sendAudioHead = YES; - [self sendAudioHeader:(LFAudioFrame*)frame]; - }else{ - [self sendAudio:frame]; - } - - } - self.debugInfo.dataFlow += frame.data.length; - if(CACurrentMediaTime()*1000 - self.debugInfo.timeStamp < 1000) { - self.debugInfo.bandwidth += frame.data.length; - if([frame isKindOfClass:[LFAudioFrame class]]){ - self.debugInfo.capturedAudioCount ++; - }else{ - self.debugInfo.capturedVideoCount ++; - } - self.debugInfo.unSendCount = self.buffer.list.count; - }else { - self.debugInfo.currentBandwidth = self.debugInfo.bandwidth; - self.debugInfo.currentCapturedAudioCount = self.debugInfo.capturedAudioCount; - self.debugInfo.currentCapturedVideoCount = self.debugInfo.capturedVideoCount; - if(self.delegate && [self.delegate respondsToSelector:@selector(socketDebug:debugInfo:)]){ - [self.delegate socketDebug:self debugInfo:self.debugInfo]; - } - - self.debugInfo.bandwidth = 0; - self.debugInfo.capturedAudioCount = 0; - self.debugInfo.capturedVideoCount = 0; - self.debugInfo.timeStamp = CACurrentMediaTime()*1000; - } - } -} - -- (void)clean{ - _isConnecting = NO; - _isReconnecting = NO; - _isSending = NO; - _isConnected = NO; - _sendAudioHead = NO; - _sendVideoHead = NO; - self.debugInfo = nil; - [self.buffer removeAllObject]; - self.retryTimes4netWorkBreaken = 0; -} - --(NSInteger) RTMP264_Connect:(char *)push_url{ - //由于摄像头的timestamp是一直在累加,需要每次得到相对时间戳 - //分配与初始化 - if(_isConnecting) return -1; - - _isConnecting = YES; - if(self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]){ - [self.delegate socketStatus:self status:LFLivePending]; - } - - if(_rtmp != NULL){ - PILI_RTMP_Close(_rtmp, &_error); - PILI_RTMP_Free(_rtmp); - } - - _rtmp = PILI_RTMP_Alloc(); - PILI_RTMP_Init(_rtmp); - - //设置URL - if (PILI_RTMP_SetupURL(_rtmp, push_url, &_error) < 0){ - //log(LOG_ERR, "RTMP_SetupURL() failed!"); - goto Failed; - } - - _rtmp->m_errorCallback = RTMPErrorCallback; - _rtmp->m_connCallback = ConnectionTimeCallback; - _rtmp->m_userData = (__bridge void*)self; - _rtmp->m_msgCounter = 1; - //设置可写,即发布流,这个函数必须在连接前使用,否则无效 - PILI_RTMP_EnableWrite(_rtmp); - - //连接服务器 - if (PILI_RTMP_Connect(_rtmp, NULL, &_error) < 0){ - goto Failed; - } - - //连接流 - if (PILI_RTMP_ConnectStream(_rtmp, 0, &_error) < 0) { - goto Failed; - } - - if(self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]){ - [self.delegate socketStatus:self status:LFLiveStart]; - } - - [self sendMetaData]; - - _isConnected = YES; - _isConnecting = NO; - _isReconnecting = NO; - _isSending = NO; - _retryTimes4netWorkBreaken = 0; - return 0; - -Failed: - PILI_RTMP_Close(_rtmp, &_error); - PILI_RTMP_Free(_rtmp); - return -1; -} - -#pragma mark -- Rtmp Send - -- (void)sendMetaData { - PILI_RTMPPacket packet; - - char pbuf[2048], *pend = pbuf+sizeof(pbuf); - - packet.m_nChannel = 0x03; // control channel (invoke) - packet.m_headerType = RTMP_PACKET_SIZE_LARGE; - packet.m_packetType = RTMP_PACKET_TYPE_INFO; - packet.m_nTimeStamp = 0; - packet.m_nInfoField2 = _rtmp->m_stream_id; - packet.m_hasAbsTimestamp = TRUE; - packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; - - char *enc = packet.m_body; - enc = AMF_EncodeString(enc, pend, &av_setDataFrame); - enc = AMF_EncodeString(enc, pend, &av_onMetaData); - - *enc++ = AMF_OBJECT; - - enc = AMF_EncodeNamedNumber(enc, pend, &av_duration, 0.0); - enc = AMF_EncodeNamedNumber(enc, pend, &av_fileSize, 0.0); - - // videosize - enc = AMF_EncodeNamedNumber(enc, pend, &av_width, _stream.videoConfiguration.videoSize.width); - enc = AMF_EncodeNamedNumber(enc, pend, &av_height, _stream.videoConfiguration.videoSize.height); - - // video - enc = AMF_EncodeNamedString(enc, pend, &av_videocodecid, &av_avc1); - - enc = AMF_EncodeNamedNumber(enc, pend, &av_videodatarate, _stream.videoConfiguration.videoBitRate / 1000.f); - enc = AMF_EncodeNamedNumber(enc, pend, &av_framerate, _stream.videoConfiguration.videoFrameRate); - - // audio - enc = AMF_EncodeNamedString(enc, pend, &av_audiocodecid, &av_mp4a); - enc = AMF_EncodeNamedNumber(enc, pend, &av_audiodatarate, _stream.audioConfiguration.audioBitrate); - - enc = AMF_EncodeNamedNumber(enc, pend, &av_audiosamplerate, _stream.audioConfiguration.audioSampleRate); - enc = AMF_EncodeNamedNumber(enc, pend, &av_audiosamplesize, 16.0); - enc = AMF_EncodeNamedBoolean(enc, pend, &av_stereo, _stream.audioConfiguration.numberOfChannels==2); - - // sdk version - enc = AMF_EncodeNamedString(enc, pend, &av_encoder, &av_SDKVersion); - - *enc++ = 0; - *enc++ = 0; - *enc++ = AMF_OBJECT_END; - - packet.m_nBodySize = enc - packet.m_body; - if(!PILI_RTMP_SendPacket(_rtmp, &packet, FALSE, &_error)) { - return; - } -} - -- (void)sendVideoHeader:(LFVideoFrame*)videoFrame { - if(!videoFrame || !videoFrame.sps || !videoFrame.pps) return; - - unsigned char * body=NULL; - NSInteger iIndex = 0; - NSInteger rtmpLength = 1024; - const char *sps = videoFrame.sps.bytes; - const char *pps = videoFrame.pps.bytes; - NSInteger sps_len = videoFrame.sps.length; - NSInteger pps_len = videoFrame.pps.length; - - body = (unsigned char*)malloc(rtmpLength); - memset(body,0,rtmpLength); - - body[iIndex++] = 0x17; - body[iIndex++] = 0x00; - - body[iIndex++] = 0x00; - body[iIndex++] = 0x00; - body[iIndex++] = 0x00; - - body[iIndex++] = 0x01; - body[iIndex++] = sps[1]; - body[iIndex++] = sps[2]; - body[iIndex++] = sps[3]; - body[iIndex++] = 0xff; - - /*sps*/ - body[iIndex++] = 0xe1; - body[iIndex++] = (sps_len >> 8) & 0xff; - body[iIndex++] = sps_len & 0xff; - memcpy(&body[iIndex],sps,sps_len); - iIndex += sps_len; - - /*pps*/ - body[iIndex++] = 0x01; - body[iIndex++] = (pps_len >> 8) & 0xff; - body[iIndex++] = (pps_len) & 0xff; - memcpy(&body[iIndex], pps, pps_len); - iIndex += pps_len; - - [self sendPacket:RTMP_PACKET_TYPE_VIDEO data:body size:iIndex nTimestamp:0]; - free(body); -} - - -- (void)sendVideo:(LFVideoFrame*)frame{ - if(!frame || !frame.data || frame.data.length < 11) return; - - NSInteger i = 0; - NSInteger rtmpLength = frame.data.length+9; - unsigned char *body = (unsigned char*)malloc(rtmpLength); - memset(body,0,rtmpLength); - - if(frame.isKeyFrame){ - body[i++] = 0x17;// 1:Iframe 7:AVC - } else{ - body[i++] = 0x27;// 2:Pframe 7:AVC - } - body[i++] = 0x01;// AVC NALU - body[i++] = 0x00; - body[i++] = 0x00; - body[i++] = 0x00; - body[i++] = (frame.data.length >> 24) & 0xff; - body[i++] = (frame.data.length >> 16) & 0xff; - body[i++] = (frame.data.length >> 8) & 0xff; - body[i++] = (frame.data.length ) & 0xff; - memcpy(&body[i],frame.data.bytes,frame.data.length); - - [self sendPacket:RTMP_PACKET_TYPE_VIDEO data:body size:(rtmpLength) nTimestamp:frame.timestamp]; - free(body); -} - --(NSInteger) sendPacket:(unsigned int)nPacketType data:(unsigned char *)data size:(NSInteger) size nTimestamp:(uint64_t) nTimestamp{ - NSInteger rtmpLength = size; - PILI_RTMPPacket rtmp_pack; - PILI_RTMPPacket_Reset(&rtmp_pack); - PILI_RTMPPacket_Alloc(&rtmp_pack,(uint32_t)rtmpLength); - - rtmp_pack.m_nBodySize = (uint32_t)size; - memcpy(rtmp_pack.m_body,data,size); - rtmp_pack.m_hasAbsTimestamp = 0; - rtmp_pack.m_packetType = nPacketType; - if(_rtmp) rtmp_pack.m_nInfoField2 = _rtmp->m_stream_id; - rtmp_pack.m_nChannel = 0x04; - rtmp_pack.m_headerType = RTMP_PACKET_SIZE_LARGE; - if (RTMP_PACKET_TYPE_AUDIO == nPacketType && size !=4){ - rtmp_pack.m_headerType = RTMP_PACKET_SIZE_MEDIUM; - } - rtmp_pack.m_nTimeStamp = (uint32_t)nTimestamp; - - NSInteger nRet = [self RtmpPacketSend:&rtmp_pack]; - - PILI_RTMPPacket_Free(&rtmp_pack); - return nRet; -} - -- (NSInteger)RtmpPacketSend:(PILI_RTMPPacket*)packet{ - if (PILI_RTMP_IsConnected(_rtmp)){ - int success = PILI_RTMP_SendPacket(_rtmp,packet,0,&_error); - if(success){ - self.isSending = NO; - [self sendFrame]; - } - return success; - } - - return -1; -} - -- (void)sendAudioHeader:(LFAudioFrame*)audioFrame{ - if(!audioFrame || !audioFrame.audioInfo) return; - - NSInteger rtmpLength = audioFrame.audioInfo.length + 2;/*spec data长度,一般是2*/ - unsigned char * body = (unsigned char*)malloc(rtmpLength); - memset(body,0,rtmpLength); - - /*AF 00 + AAC RAW data*/ - body[0] = 0xAF; - body[1] = 0x00; - memcpy(&body[2],audioFrame.audioInfo.bytes,audioFrame.audioInfo.length); /*spec_buf是AAC sequence header数据*/ - [self sendPacket:RTMP_PACKET_TYPE_AUDIO data:body size:rtmpLength nTimestamp:0]; - free(body); -} - -- (void)sendAudio:(LFFrame*)frame { - if(!frame) return; - - NSInteger rtmpLength = frame.data.length + 2;/*spec data长度,一般是2*/ - unsigned char * body = (unsigned char*)malloc(rtmpLength); - memset(body,0,rtmpLength); - - /*AF 01 + AAC RAW data*/ - body[0] = 0xAF; - body[1] = 0x01; - memcpy(&body[2],frame.data.bytes,frame.data.length); - [self sendPacket:RTMP_PACKET_TYPE_AUDIO data:body size:rtmpLength nTimestamp:frame.timestamp]; - free(body); -} - -// 断线重连 --(void) reconnect { - _isReconnecting = NO; - if(_isConnected) return; - if(_rtmp){ - PILI_RTMP_ReconnectStream(_rtmp, 0, &_error); - }else{ - [self stop]; - [self start]; - } -} - -#pragma mark -- CallBack -void RTMPErrorCallback(RTMPError *error, void *userData){ - LFStreamRtmpSocket *socket = (__bridge LFStreamRtmpSocket*)userData; - if(error->code == RTMPErrorSocketClosedByPeer){ - [socket stop]; - if(socket.delegate && [socket.delegate respondsToSelector:@selector(socketStatus:status:)]){ - [socket.delegate socketStatus:socket status:LFLiveError]; - } - }else{ - if(socket.retryTimes4netWorkBreaken++ < socket.reconnectCount && !socket.isReconnecting){ - socket.isConnected = NO; - socket.isConnecting = NO; - socket.isReconnecting = YES; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(socket.reconnectInterval * NSEC_PER_SEC)), socket.socketQueue, ^{ - [socket reconnect]; - }); - }else if(socket.retryTimes4netWorkBreaken >= socket.reconnectCount){ - if(socket.delegate && [socket.delegate respondsToSelector:@selector(socketStatus:status:)]){ - [socket.delegate socketStatus:socket status:LFLiveError]; - } - if(socket.delegate && [socket.delegate respondsToSelector:@selector(socketDidError:errorCode:)]){ - [socket.delegate socketDidError:socket errorCode:LFLiveSocketError_ReConnectTimeOut]; - } - } - } -} - -void ConnectionTimeCallback(PILI_CONNECTION_TIME* conn_time, void *userData){ - //LFStreamRtmpSocket *socket = (__bridge LFStreamRtmpSocket*)userData; -} - -#pragma mark -- Getter Setter -- (dispatch_queue_t)socketQueue{ - if(!_socketQueue){ - _socketQueue = dispatch_queue_create("com.youku.LaiFeng.live.socketQueue", NULL); - } - return _socketQueue; -} - -- (LFStreamingBuffer*)buffer{ - if(!_buffer){ - _buffer = [[LFStreamingBuffer alloc] init]; - _buffer.delegate = self; - } - return _buffer; -} - -- (LFLiveDebug*)debugInfo{ - if(!_debugInfo){ - _debugInfo = [[LFLiveDebug alloc] init]; - } - return _debugInfo; -} - -@end diff --git a/LFLiveKit/upload/LFStreamSocket.h b/LFLiveKit/upload/LFStreamSocket.h deleted file mode 100644 index f9128e55..00000000 --- a/LFLiveKit/upload/LFStreamSocket.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// LFStreamSocket.h -// LFLiveKit -// -// Created by admin on 16/5/3. -// Copyright © 2016年 倾慕. All rights reserved. -// - -#import -#import "LFLiveStreamInfo.h" -#import "LFStreamingBuffer.h" -#import "LFLiveDebug.h" - -@protocol LFStreamSocket ; -@protocol LFStreamSocketDelegate - -/** callback buffer current status (回调当前缓冲区情况,可实现相关切换帧率 码率等策略)*/ -- (void)socketBufferStatus:(nullable id)socket status:(LFLiveBuffferState)status; -/** callback socket current status (回调当前网络情况) */ -- (void)socketStatus:(nullable id)socket status:(LFLiveState)status; -/** callback socket errorcode */ -- (void)socketDidError:(nullable id)socket errorCode:(LFLiveSocketErrorCode)errorCode; -@optional -/** callback debugInfo */ -- (void)socketDebug:(nullable id)socket debugInfo:(nullable LFLiveDebug*)debugInfo; -@end - -@protocol LFStreamSocket -- (void) start; -- (void) stop; -- (void) sendFrame:(nullable LFFrame*)frame; -- (void) setDelegate:(nullable id)delegate; -@optional -- (nullable instancetype)initWithStream:(nullable LFLiveStreamInfo*)stream; -- (nullable instancetype)initWithStream:(nullable LFLiveStreamInfo*)stream videoSize:(CGSize)videoSize; -- (nullable instancetype)initWithStream:(nullable LFLiveStreamInfo*)stream videoSize:(CGSize)videoSize reconnectInterval:(NSInteger)reconnectInterval reconnectCount:(NSInteger)reconnectCount; -@end diff --git a/LFLiveKit/upload/LFStreamTcpSocket.h b/LFLiveKit/upload/LFStreamTcpSocket.h deleted file mode 100644 index d9b7da5a..00000000 --- a/LFLiveKit/upload/LFStreamTcpSocket.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// LFStreamTcpSocket.h -// LFLiveKit -// -// Created by admin on 16/5/3. -// Copyright © 2016年 倾慕. All rights reserved. -// - -#import "LFStreamSocket.h" - -@interface LFStreamTcpSocket : NSObject -#pragma mark - Initializer -///============================================================================= -/// @name Initializer -///============================================================================= -- (nullable instancetype)init UNAVAILABLE_ATTRIBUTE; -+ (nullable instancetype)new UNAVAILABLE_ATTRIBUTE; - -@end diff --git a/LFLiveKit/upload/LFStreamTcpSocket.m b/LFLiveKit/upload/LFStreamTcpSocket.m deleted file mode 100644 index 779b4a28..00000000 --- a/LFLiveKit/upload/LFStreamTcpSocket.m +++ /dev/null @@ -1,331 +0,0 @@ -// -// LFStreamTcpSocket.m -// LFLiveKit -// -// Created by admin on 16/5/3. -// Copyright © 2016年 倾慕. All rights reserved. -// - -#import "LFStreamTcpSocket.h" -#import "GCDAsyncSocket.h" -#import "LFFlvPackage.h" - -static const NSInteger RetryTimesBreaken = 20;///< 重连3分钟 3秒一次 一共60次 -static const NSInteger RetryTimesMargin = 3; -const NSInteger TCP_RECEIVE_TIMEOUT = -1; - -@interface LFStreamTcpSocket () - -@property (nonatomic, strong) GCDAsyncSocket * socket; -@property (nonatomic, strong) dispatch_queue_t socketQueue; -@property (nonatomic, strong) LFStreamingBuffer *buffer; -@property (nonatomic, strong) LFLiveStreamInfo *stream; -@property (nonatomic, weak) id delegate; -@property (nonatomic, strong) id package; -@property (nonatomic, strong) LFLiveDebug *debugInfo; -@property (nonatomic, assign) CGSize videoSize; - -@property (nonatomic, assign) BOOL isSending; -@property (nonatomic, assign) BOOL isConnecting; -@property (nonatomic, assign) BOOL isReconnecting; -@property (nonatomic, assign) BOOL isConnected; -@property (nonatomic, assign) NSInteger retryTimes4netWorkBreaken; -@property (nonatomic, assign) NSInteger reconnectInterval; -@property (nonatomic, assign) NSInteger reconnectCount; -@property (nonatomic, assign) BOOL needSendHeader; - -@end - -@implementation LFStreamTcpSocket - -- (nullable instancetype)initWithStream:(nullable LFLiveStreamInfo*)stream videoSize:(CGSize)videoSize reconnectInterval:(NSInteger)reconnectInterval reconnectCount:(NSInteger)reconnectCount{ - if(!stream) @throw [NSException exceptionWithName:@"LFStreamTcpSocket init error" reason:@"stream is nil" userInfo:nil]; - if(CGSizeEqualToSize(videoSize, CGSizeZero)) @throw [NSException exceptionWithName:@"LFStreamTcpSocket init error" reason:@"videoSize is zero" userInfo:nil]; - if(self = [super init]){ - _stream = stream; - _videoSize = videoSize; - if(reconnectInterval > 0) _reconnectInterval = reconnectInterval; - else _reconnectInterval = RetryTimesMargin; - - if(reconnectCount > 0) _reconnectCount = reconnectCount; - else _reconnectCount = RetryTimesBreaken; - } - return self; -} - -#pragma mark -- LFStreamSocket -- (void) start{ - if(!_stream) return; - if(_isConnecting) return; - if(_socket.isConnected) return; - [self clean]; - - self.debugInfo.streamId = self.stream.streamId; - self.debugInfo.uploadUrl = self.stream.url; - self.debugInfo.videoSize = self.videoSize; - self.debugInfo.isRtmp = NO; - - if(![self.socket connectToHost:_stream.host onPort:_stream.port withTimeout:5 error:nil]){ - if(self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]){ - [self.delegate socketStatus:self status:LFLiveError]; - } - if(self.delegate && [self.delegate respondsToSelector:@selector(socketDidError:errorCode:)]){ - [self.delegate socketDidError:self errorCode:LFLiveSocketError_ConnectSocket]; - } - return; - } - if(self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]){ - [self.delegate socketStatus:self status:LFLivePending]; - } - _isConnecting = YES; - -} - -- (void) stop{ - [self.socket disconnect]; - [self clean]; -} - -- (void)sendFrame:(LFFrame *)frame{ - __weak typeof(self) _self = self; - dispatch_async(self.socketQueue, ^{ - __strong typeof(_self) self = _self; - if(!frame) return; - if([frame isKindOfClass:[LFAudioFrame class]]){ - NSData *packageData = [self.package aaCPacket:(LFAudioFrame*)frame];///< 打包flv - if(!packageData) return; - frame.data = packageData; - }else{ - NSData *packageData = [self.package h264Packet:(LFVideoFrame*)frame];///< 打包flv - if(!packageData) return; - frame.data = packageData; - } - - [self.buffer appendObject:frame]; - [self sendFrame]; - }); -} - -- (void)setDelegate:(id)delegate{ - _delegate = delegate; -} - -#pragma mark -- CustomMethod -- (void)sendFrame{ - if(!self.isSending && self.buffer.list.count > 0 && _isConnected){ - self.isSending = YES; - LFFrame *frame = [self.buffer popFirstObject]; - if(self.needSendHeader){///< flvHeader 插入到队列最前面去 - NSMutableData * mutableData = [[NSMutableData alloc] init]; - [mutableData appendData:frame.header]; - [mutableData appendData:frame.data]; - frame.data = mutableData; - self.needSendHeader = NO; - } - [self.socket writeData:frame.data withTimeout:TCP_RECEIVE_TIMEOUT tag:1]; - - self.debugInfo.dataFlow += frame.data.length; - if(CACurrentMediaTime()*1000 - self.debugInfo.timeStamp < 1000) { - self.debugInfo.bandwidth += frame.data.length; - if([frame isKindOfClass:[LFAudioFrame class]]){ - self.debugInfo.capturedAudioCount ++; - }else{ - self.debugInfo.capturedVideoCount ++; - } - self.debugInfo.unSendCount = self.buffer.list.count; - }else { - self.debugInfo.currentBandwidth = self.debugInfo.bandwidth; - self.debugInfo.currentCapturedAudioCount = self.debugInfo.capturedAudioCount; - self.debugInfo.currentCapturedVideoCount = self.debugInfo.capturedVideoCount; - if(self.delegate && [self.delegate respondsToSelector:@selector(socketDebug:debugInfo:)]){ - [self.delegate socketDebug:self debugInfo:self.debugInfo]; - } - - self.debugInfo.bandwidth = 0; - self.debugInfo.capturedAudioCount = 0; - self.debugInfo.capturedVideoCount = 0; - self.debugInfo.timeStamp = CACurrentMediaTime()*1000; - } - - } -} - -- (void)clean{ - _isConnected = NO; - _isConnecting = NO; - _isReconnecting = NO; - _isSending = NO; - _retryTimes4netWorkBreaken = 0; - _needSendHeader = NO; - self.debugInfo = nil; - [self.buffer removeAllObject]; -} - -// 断线重连 --(void) reconnect { - _isReconnecting = NO; - if(_isConnected) return; - if([self.socket isConnected]) return; - - if(![self.socket connectToHost:_stream.host onPort:_stream.port withTimeout:5 error:nil]){ - if(self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]){ - [self.delegate socketStatus:self status:LFLiveError]; - } - if(self.delegate && [self.delegate respondsToSelector:@selector(socketDidError:errorCode:)]){ - [self.delegate socketDidError:self errorCode:LFLiveSocketError_ConnectSocket]; - } - return; - } -} - - -#pragma mark -- GCDAsyncSocketDelegate -- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port{ - NSLog(@"onSocket:%p didConnectToHost:%@ port:%hu", sock, host, port); - [sock readDataWithTimeout:-1 tag:0]; - if(_isConnected) return; - [self.socket writeData:self.verificationData withTimeout:-1 tag:0]; -} - -- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag { - [sock readDataWithTimeout:-1 tag:0]; - if(_isConnected) return; - if([self verificationDataValid:data]){ - NSLog(@"服务器验证成功,准备发送数据"); - _isConnected = YES; - _isConnecting = NO; - _isReconnecting = NO; - _retryTimes4netWorkBreaken = 0;// 计数器清零 - _needSendHeader = YES; - self.isSending = NO; - if(self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]){ - [self.delegate socketStatus:self status:LFLiveStart]; - } - }else{ - NSLog(@"服务器验证失败"); - [self clean]; - [self.socket disconnect]; - - if(self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]){ - [self.delegate socketStatus:self status:LFLiveError]; - } - if(self.delegate && [self.delegate respondsToSelector:@selector(socketDidError:errorCode:)]){ - [self.delegate socketDidError:self errorCode:LFLiveSocketError_Verification]; - } - } -} - -- (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err { - NSLog(@"onSocket:%p socketDidDisconnectWithError:%@", sock, err); - if(err){ - if(self.retryTimes4netWorkBreaken++ < _reconnectCount && !self.isReconnecting){ - _isConnected = NO; - _isConnecting = NO; - _isReconnecting = YES; - - [self.socket disconnect]; - ///< 连接超时 - if(err.code == 3){ - if(self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]){ - [self.delegate socketStatus:self status:LFLiveError]; - } - if(self.delegate && [self.delegate respondsToSelector:@selector(socketDidError:errorCode:)]){ - [self.delegate socketDidError:self errorCode:LFLiveSocketError_ConnectSocket]; - } - return; - } - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(_reconnectInterval * NSEC_PER_SEC)), self.socketQueue, ^{ - [self reconnect]; - }); - - if(self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]){ - [self.delegate socketStatus:self status:LFLivePending]; - } - }else if(self.retryTimes4netWorkBreaken >= _reconnectCount){ - if(self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]){ - [self.delegate socketStatus:self status:LFLiveError]; - } - if(self.delegate && [self.delegate respondsToSelector:@selector(socketDidError:errorCode:)]){ - [self.delegate socketDidError:self errorCode:LFLiveSocketError_ReConnectTimeOut]; - } - } - }else{ - [self clean]; - if(self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]){ - [self.delegate socketStatus:self status:LFLiveStop]; - } - } -} - -- (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag{ - if(tag > 0){ - self.isSending = NO; - [self sendFrame]; - } -} - -#pragma mark --BufferDelegate -- (void)streamingBuffer:(nullable LFStreamingBuffer*)buffer bufferState:(LFLiveBuffferState)state{ - if(self.isConnected){ - if(self.delegate && [self.delegate respondsToSelector:@selector(socketBufferStatus:status:)]){ - [self.delegate socketBufferStatus:self status:state]; - } - } -} - -#pragma mark -- Getter Setter -- (dispatch_queue_t)socketQueue{ - if(!_socketQueue){ - _socketQueue = dispatch_queue_create("com.youku.LaiFeng.live.socketQueue", NULL); - } - return _socketQueue; -} - -- (GCDAsyncSocket*)socket{ - if(!_socket){ - _socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:self.socketQueue socketQueue:self.socketQueue]; - } - return _socket; -} - -- (LFStreamingBuffer*)buffer{ - if(!_buffer){ - _buffer = [[LFStreamingBuffer alloc] init]; - _buffer.delegate = self; - } - return _buffer; -} - -- (id)package{ - if(!_package){ - _package = [[LFFlvPackage alloc] initWithVideoSize:self.videoSize]; - } - return _package; -} - -- (LFLiveDebug*)debugInfo{ - if(!_debugInfo){ - _debugInfo = [[LFLiveDebug alloc] init]; - } - return _debugInfo; -} - -#pragma mark -- 服务器验证 -- (NSData*)verificationData{ - /** 结构体专为NSData **/ - if(!self.stream) return nil; - #warning TODO send verficationData to server - return nil; -} - -- (BOOL)verificationDataValid:(NSData*)data{ - /** NSData专为结构体 **/ - if(!self.stream) return NO; - if(!data) return NO; - #warning TODO server give client data,verification - return NO; -} - - -@end diff --git a/LFLiveKit/upload/NSMutableArray+LFAdd.h b/LFLiveKit/upload/NSMutableArray+LFAdd.h deleted file mode 100755 index 3b463356..00000000 --- a/LFLiveKit/upload/NSMutableArray+LFAdd.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// NSMutableArray+LFAdd.h -// YYKit -// -// Created by admin on 16/5/20. -// Copyright © 2016年 倾慕. All rights reserved. -// - -#import - -@interface NSMutableArray (YYAdd) - -/** - Removes and returns the object with the lowest-valued index in the array. - If the array is empty, it just returns nil. - - @return The first object, or nil. - */ -- (nullable id)lfPopFirstObject; - -@end diff --git a/LFLiveKitDemo/.gitignore b/LFLiveKitDemo/.gitignore deleted file mode 100644 index 382f8343..00000000 --- a/LFLiveKitDemo/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ - -#CocoaPods -Pods/ -Podfile.lock \ No newline at end of file diff --git a/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 122805a2..00000000 --- a/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate b/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100644 index a6cfc161..00000000 Binary files a/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ diff --git a/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/xcuserdata/admin.xcuserdatad/xcschemes/LFLiveKitDemo.xcscheme b/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/xcuserdata/admin.xcuserdatad/xcschemes/LFLiveKitDemo.xcscheme deleted file mode 100644 index 19a8f37e..00000000 --- a/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/xcuserdata/admin.xcuserdatad/xcschemes/LFLiveKitDemo.xcscheme +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/xcuserdata/admin.xcuserdatad/xcschemes/xcschememanagement.plist b/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/xcuserdata/admin.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index 16e8485c..00000000 --- a/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/xcuserdata/admin.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,32 +0,0 @@ - - - - - SchemeUserState - - LFLiveKitDemo.xcscheme - - orderHint - 0 - - - SuppressBuildableAutocreation - - 840762EB1D07C7D0000FD0BF - - primary - - - 840763041D07C7D0000FD0BF - - primary - - - 8407630F1D07C7D0000FD0BF - - primary - - - - - diff --git a/LFLiveKitDemo/LFLiveKitDemo.xcworkspace/contents.xcworkspacedata b/LFLiveKitDemo/LFLiveKitDemo.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 3d8408a1..00000000 --- a/LFLiveKitDemo/LFLiveKitDemo.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - diff --git a/LFLiveKitDemo/LFLiveKitDemo.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate b/LFLiveKitDemo/LFLiveKitDemo.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100644 index cb63c595..00000000 Binary files a/LFLiveKitDemo/LFLiveKitDemo.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ diff --git a/LFLiveKitDemo/LFLiveKitDemo/LFLivePreview.m b/LFLiveKitDemo/LFLiveKitDemo/LFLivePreview.m deleted file mode 100755 index f449d64f..00000000 --- a/LFLiveKitDemo/LFLiveKitDemo/LFLivePreview.m +++ /dev/null @@ -1,325 +0,0 @@ -// -// LFLivePreview.m -// LFLiveKit -// -// Created by 倾慕 on 16/5/2. -// Copyright © 2016年 live Interactive. All rights reserved. -// - -#import "LFLivePreview.h" -#import "UIControl+YYAdd.h" -#import "UIView+YYAdd.h" -#import "LFLiveSession.h" - -@interface LFLivePreview () - -@property (nonatomic, strong) UIButton *beautyButton; -@property (nonatomic, strong) UIButton *cameraButton; -@property (nonatomic, strong) UIButton *closeButton; -@property (nonatomic, strong) UIButton *startLiveButton; -@property (nonatomic, strong) UIView *containerView; -@property (nonatomic, strong) LFLiveDebug *debugInfo; -@property (nonatomic, strong) LFLiveSession *session; -@property (nonatomic, strong) UILabel *stateLabel; - -@end - -@implementation LFLivePreview - -- (instancetype)initWithFrame:(CGRect)frame{ - if(self = [super initWithFrame:frame]){ - self.backgroundColor = [UIColor clearColor]; - [self requestAccessForVideo]; - [self requestAccessForAudio]; - [self addSubview:self.containerView]; - [self.containerView addSubview:self.stateLabel]; - [self.containerView addSubview:self.closeButton]; - [self.containerView addSubview:self.cameraButton]; - [self.containerView addSubview:self.beautyButton]; - [self.containerView addSubview:self.startLiveButton]; - } - return self; -} - -#pragma mark -- Public Method -- (void)requestAccessForVideo{ - __weak typeof(self) _self = self; - AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; - switch (status) { - case AVAuthorizationStatusNotDetermined:{ - // 许可对话没有出现,发起授权许可 - [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { - if (granted) { - dispatch_async(dispatch_get_main_queue(), ^{ - [_self.session setRunning:YES]; - }); - } - }]; - break; - } - case AVAuthorizationStatusAuthorized:{ - // 已经开启授权,可继续 - [_self.session setRunning:YES]; - break; - } - case AVAuthorizationStatusDenied: - case AVAuthorizationStatusRestricted: - // 用户明确地拒绝授权,或者相机设备无法访问 - - break; - default: - break; - } -} - -- (void)requestAccessForAudio{ - AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]; - switch (status) { - case AVAuthorizationStatusNotDetermined:{ - [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) { - }]; - break; - } - case AVAuthorizationStatusAuthorized:{ - break; - } - case AVAuthorizationStatusDenied: - case AVAuthorizationStatusRestricted: - break; - default: - break; - } -} - - -#pragma mark -- LFStreamingSessionDelegate -/** live status changed will callback */ -- (void)liveSession:(nullable LFLiveSession *)session liveStateDidChange:(LFLiveState)state{ - NSLog(@"liveStateDidChange: %ld", state); - switch (state) { - case LFLiveReady: - _stateLabel.text = @"未连接"; - break; - case LFLivePending: - _stateLabel.text = @"连接中"; - break; - case LFLiveStart: - _stateLabel.text = @"已连接"; - break; - case LFLiveError: - _stateLabel.text = @"连接错误"; - break; - case LFLiveStop: - _stateLabel.text = @"未连接"; - break; - default: - break; - } -} - -/** live debug info callback */ -- (void)liveSession:(nullable LFLiveSession *)session debugInfo:(nullable LFLiveDebug*)debugInfo{ - NSLog(@"debugInfo: %lf", debugInfo.dataFlow); -} - -/** callback socket errorcode */ -- (void)liveSession:(nullable LFLiveSession*)session errorCode:(LFLiveSocketErrorCode)errorCode{ - NSLog(@"errorCode: %ld", errorCode); -} - -#pragma mark -- Getter Setter -- (LFLiveSession*)session{ - if(!_session){ - /***  默认分辨率368 * 640 音频:44.1 iphone6以上48 双声道 方向竖屏 ***/ - _session = [[LFLiveSession alloc] initWithAudioConfiguration:[LFLiveAudioConfiguration defaultConfiguration] videoConfiguration:[LFLiveVideoConfiguration defaultConfigurationForQuality:LFLiveVideoQuality_Medium2] liveType:LFLiveRTMP]; - _session.delegate = self; - - /**   自己定制单声道 */ - /* - LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; - audioConfiguration.numberOfChannels = 1; - audioConfiguration.audioBitrate = LFLiveAudioBitRate_64Kbps; - audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; - _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:[LFLiveVideoConfiguration defaultConfiguration] liveType:LFLiveRTMP]; - */ - - /**   自己定制高质量音频96K */ - /* - LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; - audioConfiguration.numberOfChannels = 2; - audioConfiguration.audioBitrate = LFLiveAudioBitRate_96Kbps; - audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; - _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:[LFLiveVideoConfiguration defaultConfiguration] liveType:LFLiveRTMP]; - */ - - /**   自己定制高质量音频96K 分辨率设置为540*960 方向竖屏 */ - - /* - LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; - audioConfiguration.numberOfChannels = 2; - audioConfiguration.audioBitrate = LFLiveAudioBitRate_96Kbps; - audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; - - LFLiveVideoConfiguration *videoConfiguration = [LFLiveVideoConfiguration new]; - videoConfiguration.videoSize = CGSizeMake(540, 960); - videoConfiguration.videoBitRate = 800*1024; - videoConfiguration.videoMaxBitRate = 1000*1024; - videoConfiguration.videoMinBitRate = 500*1024; - videoConfiguration.videoFrameRate = 24; - videoConfiguration.videoMaxKeyframeInterval = 48; - videoConfiguration.orientation = UIInterfaceOrientationPortrait; - videoConfiguration.sessionPreset = LFCaptureSessionPreset540x960; - - _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:videoConfiguration liveType:LFLiveRTMP]; - */ - - - /**   自己定制高质量音频128K 分辨率设置为720*1280 方向竖屏 */ - - /* - LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; - audioConfiguration.numberOfChannels = 2; - audioConfiguration.audioBitrate = LFLiveAudioBitRate_128Kbps; - audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; - - LFLiveVideoConfiguration *videoConfiguration = [LFLiveVideoConfiguration new]; - videoConfiguration.videoSize = CGSizeMake(720, 1280); - videoConfiguration.videoBitRate = 800*1024; - videoConfiguration.videoMaxBitRate = 1000*1024; - videoConfiguration.videoMinBitRate = 500*1024; - videoConfiguration.videoFrameRate = 15; - videoConfiguration.videoMaxKeyframeInterval = 30; - videoConfiguration.orientation = UIInterfaceOrientationPortrait; - videoConfiguration.sessionPreset = LFCaptureSessionPreset720x1280; - - _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:videoConfiguration liveType:LFLiveRTMP]; - */ - - - /**   自己定制高质量音频128K 分辨率设置为720*1280 方向横屏 */ - - /* - LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; - audioConfiguration.numberOfChannels = 2; - audioConfiguration.audioBitrate = LFLiveAudioBitRate_128Kbps; - audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; - - LFLiveVideoConfiguration *videoConfiguration = [LFLiveVideoConfiguration new]; - videoConfiguration.videoSize = CGSizeMake(1280, 720); - videoConfiguration.videoBitRate = 800*1024; - videoConfiguration.videoMaxBitRate = 1000*1024; - videoConfiguration.videoMinBitRate = 500*1024; - videoConfiguration.videoFrameRate = 15; - videoConfiguration.videoMaxKeyframeInterval = 30; - videoConfiguration.orientation = UIInterfaceOrientationLandscapeLeft; - videoConfiguration.sessionPreset = LFCaptureSessionPreset720x1280; - - _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:videoConfiguration liveType:LFLiveRTMP]; - */ - - - _session.running = YES; - _session.preView = self; - } - return _session; -} - -- (UIView*)containerView{ - if(!_containerView){ - _containerView = [UIView new]; - _containerView.frame = self.bounds; - _containerView.backgroundColor = [UIColor clearColor]; - _containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - } - return _containerView; -} - -- (UILabel*)stateLabel{ - if(!_stateLabel){ - _stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 80, 40)]; - _stateLabel.text = @"未连接"; - _stateLabel.textColor = [UIColor whiteColor]; - _stateLabel.font = [UIFont boldSystemFontOfSize:14.f]; - } - return _stateLabel; -} - -- (UIButton*)closeButton{ - if(!_closeButton){ - _closeButton = [UIButton new]; - _closeButton.size = CGSizeMake(44, 44); - _closeButton.left = self.width - 10 - _closeButton.width; - _closeButton.top = 20; - [_closeButton setImage:[UIImage imageNamed:@"close_preview"] forState:UIControlStateNormal]; - _closeButton.exclusiveTouch = YES; - [_closeButton addBlockForControlEvents:UIControlEventTouchUpInside block:^(id sender) { - - }]; - } - return _closeButton; -} - -- (UIButton*)cameraButton{ - if(!_cameraButton){ - _cameraButton = [UIButton new]; - _cameraButton.size = CGSizeMake(44, 44); - _cameraButton.origin = CGPointMake(_closeButton.left - 10 - _cameraButton.width, 20); - [_cameraButton setImage:[UIImage imageNamed:@"camra_preview"] forState:UIControlStateNormal]; - _cameraButton.exclusiveTouch = YES; - __weak typeof(self) _self = self; - [_cameraButton addBlockForControlEvents:UIControlEventTouchUpInside block:^(id sender) { - AVCaptureDevicePosition devicePositon = _self.session.captureDevicePosition; - _self.session.captureDevicePosition = (devicePositon == AVCaptureDevicePositionBack) ? AVCaptureDevicePositionFront : AVCaptureDevicePositionBack; - }]; - } - return _cameraButton; -} - -- (UIButton*)beautyButton{ - if(!_beautyButton){ - _beautyButton = [UIButton new]; - _beautyButton.size = CGSizeMake(44, 44); - _beautyButton.origin = CGPointMake(_cameraButton.left - 10 - _beautyButton.width,20); - [_beautyButton setImage:[UIImage imageNamed:@"camra_beauty"] forState:UIControlStateSelected]; - [_beautyButton setImage:[UIImage imageNamed:@"camra_beauty_close"] forState:UIControlStateNormal]; - _beautyButton.exclusiveTouch = YES; - __weak typeof(self) _self = self; - [_beautyButton addBlockForControlEvents:UIControlEventTouchUpInside block:^(id sender) { - _self.session.beautyFace = !_self.session.beautyFace; - _self.beautyButton.selected = !_self.session.beautyFace; - }]; - } - return _beautyButton; -} - -- (UIButton*)startLiveButton{ - if(!_startLiveButton){ - _startLiveButton = [UIButton new]; - _startLiveButton.size = CGSizeMake(self.width - 60, 44); - _startLiveButton.left = 30; - _startLiveButton.bottom = self.height - 50; - _startLiveButton.layer.cornerRadius = _startLiveButton.height/2; - [_startLiveButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; - [_startLiveButton.titleLabel setFont:[UIFont systemFontOfSize:16]]; - [_startLiveButton setTitle:@"开始直播" forState:UIControlStateNormal]; - [_startLiveButton setBackgroundColor:[UIColor colorWithRed:50 green:32 blue:245 alpha:1]]; - _startLiveButton.exclusiveTouch = YES; - __weak typeof(self) _self = self; - [_startLiveButton addBlockForControlEvents:UIControlEventTouchUpInside block:^(id sender) { - _self.startLiveButton.selected = !_self.startLiveButton.selected; - if(_self.startLiveButton.selected){ - [_self.startLiveButton setTitle:@"结束直播" forState:UIControlStateNormal]; - LFLiveStreamInfo *stream = [LFLiveStreamInfo new]; - stream.url = @"rtmp://30.96.179.95:1935/live/1234"; - //stream.url = @"rtmp://daniulive.com:1935/live/stream2399"; - [_self.session startLive:stream]; - }else{ - [_self.startLiveButton setTitle:@"开始直播" forState:UIControlStateNormal]; - [_self.session stopLive]; - } - }]; - } - return _startLiveButton; -} - -@end diff --git a/LFLiveKitDemo/LFLiveKitDemo/Podfile b/LFLiveKitDemo/LFLiveKitDemo/Podfile deleted file mode 100755 index a39728ec..00000000 --- a/LFLiveKitDemo/LFLiveKitDemo/Podfile +++ /dev/null @@ -1,8 +0,0 @@ -source 'https://github.com/CocoaPods/Specs.git' -platform :ios,'8.0' - -target "LFLiveKitDemo" do - -pod 'LFLiveKit', '~> 1.5.2' - -end \ No newline at end of file diff --git a/LFLiveKitDemo/Podfile b/LFLiveKitDemo/Podfile deleted file mode 100755 index a39728ec..00000000 --- a/LFLiveKitDemo/Podfile +++ /dev/null @@ -1,8 +0,0 @@ -source 'https://github.com/CocoaPods/Specs.git' -platform :ios,'8.0' - -target "LFLiveKitDemo" do - -pod 'LFLiveKit', '~> 1.5.2' - -end \ No newline at end of file diff --git a/LFLiveKitTests/LFLiveKitTests.m b/LFLiveKitTests/LFLiveKitTests.m deleted file mode 100644 index 2c9c54b4..00000000 --- a/LFLiveKitTests/LFLiveKitTests.m +++ /dev/null @@ -1,39 +0,0 @@ -// -// LFLiveKitTests.m -// LFLiveKitTests -// -// Created by admin on 16/6/2. -// Copyright © 2016年 admin. All rights reserved. -// - -#import - -@interface LFLiveKitTests : XCTestCase - -@end - -@implementation LFLiveKitTests - -- (void)setUp { - [super setUp]; - // Put setup code here. This method is called before the invocation of each test method in the class. -} - -- (void)tearDown { - // Put teardown code here. This method is called after the invocation of each test method in the class. - [super tearDown]; -} - -- (void)testExample { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. -} - -- (void)testPerformanceExample { - // This is an example of a performance test case. - [self measureBlock:^{ - // Put the code you want to measure the time of here. - }]; -} - -@end diff --git a/Podfile b/Podfile deleted file mode 100755 index 83e7bfa0..00000000 --- a/Podfile +++ /dev/null @@ -1,10 +0,0 @@ -source 'https://github.com/CocoaPods/Specs.git' -platform :ios,'8.0' - -target "LFLiveKit" do - -pod 'CocoaAsyncSocket', '~> 7.4.1' -pod 'pili-librtmp', '~> 1.0.2' -pod 'LMGPUImage', '~> 0.1.9' - -end \ No newline at end of file diff --git a/README.md b/README.md index 3502436d..e34a28a3 100644 --- a/README.md +++ b/README.md @@ -1,101 +1,145 @@ +LFLiveKit +============== +![icon~](https://raw.github.com/LaiFengiOS/LFLiveKit/master/samples/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 IOS mobile phone push code,Default format support RTMP and FLV,At the same time, the structure is very easy to extend. +**LFLiveKit is a opensource RTMP streaming SDK for iOS.** + +## Features + +- [x] Background recording +- [x] Support horizontal vertical recording +- [x] Support Beauty Face With GPUImage +- [x] Support H264+AAC Hardware Encoding +- [x] Drop frames on bad network +- [x] Dynamic switching rate +- [x] Audio configuration +- [x] Video configuration +- [x] RTMP Transport +- [x] Switch camera position +- [x] Audio Mute +- [x] Support Send Buffer +- [x] Support WaterMark +- [x] Swift Support +- [x] Support Single Video or Audio +- [x] Support External input video or audio(Screen recording or Peripheral) +- [ ] ~~FLV package and send~~ + +## Requirements + - iOS 7.0+ + - Xcode 7.3 + +## Installation + +#### CocoaPods + # To integrate LFLiveKit into your Xcode project using CocoaPods, specify it in your Podfile: -Podfile - 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: + # Then, run the following command: $ pod install -Functional - - Background recording - Support horizontal vertical recording - GPUImage Beauty - H264 Hard coding - AAC Hard coding - Weak network lost frame - Dynamic switching rate - Audio configuration - Video configuration - RTMP Transport - Switch camera - Audio Mute - Support Send Buffer - FLV package and send - +#### Carthage + 1. Add `github "LaiFengiOS/LFLiveKit"` to your Cartfile. + 2. Run `carthage update --platform ios` and add the framework to your project. + 3. Import \. -Architecture - capture: LFAudioCapture and LFVideoCapture - encode: LFHardwareAudioEncoder and LFHardwareVideoEncoder - publish: LFStreamRtmpSocket LFStreamTcpSocket - -Usage - - - (LFLiveSession*)session{ - if(!_session){ -_session = [[LFLiveSession alloc] initWithAudioConfiguration:[LFLiveAudioConfiguration defaultConfiguration] videoConfiguration:[LFLiveVideoConfiguration defaultConfiguration] liveType:LFLiveRTMP]; - _session.running = YES; - _session.preView = self; - } - return _session; - } +#### Manually + + 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 + * libstdc++ - - (LFLiveSession*)session{ - if(!_session){ - LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; - audioConfiguration.numberOfChannels = 2; - audioConfiguration.audioBitrate = LFLiveAudioBitRate_128Kbps; - audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; - - LFLiveVideoConfiguration *videoConfiguration = [LFLiveVideoConfiguration new]; - videoConfiguration.videoSize = CGSizeMake(1280, 720); - videoConfiguration.videoBitRate = 800*1024; - videoConfiguration.videoMaxBitRate = 1000*1024; - videoConfiguration.videoMinBitRate = 500*1024; - videoConfiguration.videoFrameRate = 15; - videoConfiguration.videoMaxKeyframeInterval = 30; - videoConfiguration.orientation = UIInterfaceOrientationLandscapeLeft; - videoConfiguration.sessionPreset = LFCaptureSessionPreset720x1280; - - _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:videoConfiguration liveType:LFLiveRTMP]; - _session.running = YES; - _session.preView = self; - } - return _session; +## Usage example + +#### Objective-C +```objc +- (LFLiveSession*)session { + if (!_session) { + _session = [[LFLiveSession alloc] initWithAudioConfiguration:[LFLiveAudioConfiguration defaultConfiguration] videoConfiguration:[LFLiveVideoConfiguration defaultConfiguration]]; + _session.preView = self; + _session.delegate = self; } - + return _session; +} + +- (void)startLive { LFLiveStreamInfo *streamInfo = [LFLiveStreamInfo new]; streamInfo.url = @"your server rtmp url"; [self.session startLive:streamInfo]; - [self.session stopLive]; - - 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; - - License - - LFLiveKit is released under the MIT license. See LICENSE for details. - - +} +- (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 +```swift +// 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. + * 2.2.4.3 + * CHANGE: modify bugs,support swift import. + * 2.5 + * CHANGE: modify bugs,support bitcode. + + +## License + **LFLiveKit is released under the MIT license. See LICENSE for details.** diff --git a/samples/Icon.png b/samples/Icon.png new file mode 100644 index 00000000..2fe52d75 Binary files /dev/null and b/samples/Icon.png differ diff --git a/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.pbxproj b/samples/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.pbxproj similarity index 51% rename from LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.pbxproj rename to samples/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.pbxproj index 7c9f92df..984880d6 100644 --- a/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.pbxproj +++ b/samples/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.pbxproj @@ -7,177 +7,160 @@ objects = { /* Begin PBXBuildFile section */ - 57B42059E84CC681C5C99B68 /* libPods-LFLiveKitDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D506B5639A1D45519536773 /* libPods-LFLiveKitDemo.a */; }; - 840762F11D07C7D0000FD0BF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 840762F01D07C7D0000FD0BF /* main.m */; }; - 840762F41D07C7D0000FD0BF /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 840762F31D07C7D0000FD0BF /* AppDelegate.m */; }; - 840762F71D07C7D0000FD0BF /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 840762F61D07C7D0000FD0BF /* ViewController.m */; }; - 840762FA1D07C7D0000FD0BF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 840762F81D07C7D0000FD0BF /* Main.storyboard */; }; - 840762FC1D07C7D0000FD0BF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 840762FB1D07C7D0000FD0BF /* Assets.xcassets */; }; - 840762FF1D07C7D0000FD0BF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 840762FD1D07C7D0000FD0BF /* LaunchScreen.storyboard */; }; - 840763291D07C894000FD0BF /* UIControl+YYAdd.m in Sources */ = {isa = PBXBuildFile; fileRef = 840763241D07C894000FD0BF /* UIControl+YYAdd.m */; }; - 8407632A1D07C894000FD0BF /* UIView+YYAdd.m in Sources */ = {isa = PBXBuildFile; fileRef = 840763261D07C894000FD0BF /* UIView+YYAdd.m */; }; - 8407632B1D07C894000FD0BF /* LFLivePreview.m in Sources */ = {isa = PBXBuildFile; fileRef = 840763281D07C894000FD0BF /* LFLivePreview.m */; }; - 840763351D07C899000FD0BF /* camra_beauty@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 8407632D1D07C899000FD0BF /* camra_beauty@2x.png */; }; - 840763361D07C899000FD0BF /* camra_beauty@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 8407632E1D07C899000FD0BF /* camra_beauty@3x.png */; }; - 840763371D07C899000FD0BF /* camra_beauty_close@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 8407632F1D07C899000FD0BF /* camra_beauty_close@2x.png */; }; - 840763381D07C899000FD0BF /* camra_beauty_close@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 840763301D07C899000FD0BF /* camra_beauty_close@3x.png */; }; - 840763391D07C899000FD0BF /* camra_preview@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 840763311D07C899000FD0BF /* camra_preview@2x.png */; }; - 8407633A1D07C899000FD0BF /* camra_preview@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 840763321D07C899000FD0BF /* camra_preview@3x.png */; }; - 8407633B1D07C899000FD0BF /* close_preview@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 840763331D07C899000FD0BF /* close_preview@2x.png */; }; - 8407633C1D07C899000FD0BF /* close_preview@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 840763341D07C899000FD0BF /* close_preview@3x.png */; }; + 84D8B42B1D75778B00752B56 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B42A1D75778B00752B56 /* main.m */; }; + 84D8B42E1D75778B00752B56 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B42D1D75778B00752B56 /* AppDelegate.m */; }; + 84D8B4311D75778B00752B56 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B4301D75778B00752B56 /* ViewController.m */; }; + 84D8B4341D75778B00752B56 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4321D75778B00752B56 /* Main.storyboard */; }; + 84D8B4361D75778B00752B56 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4351D75778B00752B56 /* Assets.xcassets */; }; + 84D8B4391D75778B00752B56 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4371D75778B00752B56 /* LaunchScreen.storyboard */; }; + 84D8B44B1D75781200752B56 /* LFLivePreview.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B44A1D75781200752B56 /* LFLivePreview.m */; }; + 84D8B45B1D75782700752B56 /* UIControl+YYAdd.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B44E1D75782700752B56 /* UIControl+YYAdd.m */; }; + 84D8B45C1D75782700752B56 /* UIView+YYAdd.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B4501D75782700752B56 /* UIView+YYAdd.m */; }; + 84D8B45D1D75782700752B56 /* camra_beauty@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4521D75782700752B56 /* camra_beauty@2x.png */; }; + 84D8B45E1D75782700752B56 /* camra_beauty@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4531D75782700752B56 /* camra_beauty@3x.png */; }; + 84D8B45F1D75782700752B56 /* camra_beauty_close@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4541D75782700752B56 /* camra_beauty_close@2x.png */; }; + 84D8B4601D75782700752B56 /* camra_beauty_close@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4551D75782700752B56 /* camra_beauty_close@3x.png */; }; + 84D8B4611D75782700752B56 /* camra_preview@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4561D75782700752B56 /* camra_preview@2x.png */; }; + 84D8B4621D75782700752B56 /* camra_preview@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4571D75782700752B56 /* camra_preview@3x.png */; }; + 84D8B4631D75782700752B56 /* close_preview@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4581D75782700752B56 /* close_preview@2x.png */; }; + 84D8B4641D75782700752B56 /* close_preview@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4591D75782700752B56 /* close_preview@3x.png */; }; + 84D8B4651D75782700752B56 /* ios-29x29.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B45A1D75782700752B56 /* ios-29x29.png */; }; + 84D8B4CF1D757F0700752B56 /* libstdc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D8B4CE1D757F0700752B56 /* libstdc++.tbd */; }; + BC8B37EEE1CEEF9B5614DC91 /* libPods-LFLiveKitDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B1CCEEE06FCFAF75D105A51 /* libPods-LFLiveKitDemo.a */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 195672426061368F86F1F4FA /* 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 = ""; }; - 5D506B5639A1D45519536773 /* libPods-LFLiveKitDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LFLiveKitDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - 7FAA55DD93CD7AB58E7A977A /* 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 = ""; }; - 840762EC1D07C7D0000FD0BF /* LFLiveKitDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LFLiveKitDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 840762F01D07C7D0000FD0BF /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; - 840762F21D07C7D0000FD0BF /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - 840762F31D07C7D0000FD0BF /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - 840762F51D07C7D0000FD0BF /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; - 840762F61D07C7D0000FD0BF /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; - 840762F91D07C7D0000FD0BF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; - 840762FB1D07C7D0000FD0BF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 840762FE1D07C7D0000FD0BF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; - 840763001D07C7D0000FD0BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 840763091D07C7D0000FD0BF /* LFLiveKitDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LFLiveKitDemoTests.m; sourceTree = ""; }; - 8407630B1D07C7D0000FD0BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 840763141D07C7D0000FD0BF /* LFLiveKitDemoUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LFLiveKitDemoUITests.m; sourceTree = ""; }; - 840763161D07C7D0000FD0BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 840763231D07C894000FD0BF /* UIControl+YYAdd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIControl+YYAdd.h"; sourceTree = ""; }; - 840763241D07C894000FD0BF /* UIControl+YYAdd.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIControl+YYAdd.m"; sourceTree = ""; }; - 840763251D07C894000FD0BF /* UIView+YYAdd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+YYAdd.h"; sourceTree = ""; }; - 840763261D07C894000FD0BF /* UIView+YYAdd.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+YYAdd.m"; sourceTree = ""; }; - 840763271D07C894000FD0BF /* LFLivePreview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFLivePreview.h; sourceTree = ""; }; - 840763281D07C894000FD0BF /* LFLivePreview.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFLivePreview.m; sourceTree = ""; }; - 8407632D1D07C899000FD0BF /* camra_beauty@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty@2x.png"; sourceTree = ""; }; - 8407632E1D07C899000FD0BF /* camra_beauty@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty@3x.png"; sourceTree = ""; }; - 8407632F1D07C899000FD0BF /* camra_beauty_close@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty_close@2x.png"; sourceTree = ""; }; - 840763301D07C899000FD0BF /* camra_beauty_close@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty_close@3x.png"; sourceTree = ""; }; - 840763311D07C899000FD0BF /* camra_preview@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_preview@2x.png"; sourceTree = ""; }; - 840763321D07C899000FD0BF /* camra_preview@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_preview@3x.png"; sourceTree = ""; }; - 840763331D07C899000FD0BF /* close_preview@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@2x.png"; sourceTree = ""; }; - 840763341D07C899000FD0BF /* close_preview@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@3x.png"; sourceTree = ""; }; + 289A9C4510CD7EA6F4CE9897 /* 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 = ""; }; + 5B1CCEEE06FCFAF75D105A51 /* libPods-LFLiveKitDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LFLiveKitDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 84D8B4261D75778B00752B56 /* LFLiveKitDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LFLiveKitDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 84D8B42A1D75778B00752B56 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 84D8B42C1D75778B00752B56 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 84D8B42D1D75778B00752B56 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 84D8B42F1D75778B00752B56 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + 84D8B4301D75778B00752B56 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 84D8B4331D75778B00752B56 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 84D8B4351D75778B00752B56 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 84D8B4381D75778B00752B56 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 84D8B43A1D75778B00752B56 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 84D8B4491D75781200752B56 /* LFLivePreview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFLivePreview.h; sourceTree = ""; }; + 84D8B44A1D75781200752B56 /* LFLivePreview.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFLivePreview.m; sourceTree = ""; }; + 84D8B44D1D75782700752B56 /* UIControl+YYAdd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIControl+YYAdd.h"; sourceTree = ""; }; + 84D8B44E1D75782700752B56 /* UIControl+YYAdd.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIControl+YYAdd.m"; sourceTree = ""; }; + 84D8B44F1D75782700752B56 /* UIView+YYAdd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+YYAdd.h"; sourceTree = ""; }; + 84D8B4501D75782700752B56 /* UIView+YYAdd.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+YYAdd.m"; sourceTree = ""; }; + 84D8B4521D75782700752B56 /* camra_beauty@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty@2x.png"; sourceTree = ""; }; + 84D8B4531D75782700752B56 /* camra_beauty@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty@3x.png"; sourceTree = ""; }; + 84D8B4541D75782700752B56 /* camra_beauty_close@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty_close@2x.png"; sourceTree = ""; }; + 84D8B4551D75782700752B56 /* camra_beauty_close@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty_close@3x.png"; sourceTree = ""; }; + 84D8B4561D75782700752B56 /* camra_preview@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_preview@2x.png"; sourceTree = ""; }; + 84D8B4571D75782700752B56 /* camra_preview@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_preview@3x.png"; sourceTree = ""; }; + 84D8B4581D75782700752B56 /* close_preview@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@2x.png"; sourceTree = ""; }; + 84D8B4591D75782700752B56 /* close_preview@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@3x.png"; sourceTree = ""; }; + 84D8B45A1D75782700752B56 /* ios-29x29.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ios-29x29.png"; sourceTree = ""; }; + 84D8B4CE1D757F0700752B56 /* libstdc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libstdc++.tbd"; path = "usr/lib/libstdc++.tbd"; sourceTree = SDKROOT; }; + 96E1231310083A3881AD2AB6 /* 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 = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ - 840762E91D07C7D0000FD0BF /* Frameworks */ = { + 84D8B4231D75778B00752B56 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 57B42059E84CC681C5C99B68 /* libPods-LFLiveKitDemo.a in Frameworks */, + 84D8B4CF1D757F0700752B56 /* libstdc++.tbd in Frameworks */, + BC8B37EEE1CEEF9B5614DC91 /* libPods-LFLiveKitDemo.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 713DA9EBCA308093C74917F9 /* Frameworks */ = { + 65E0CF98FF954863E543A0E1 /* Frameworks */ = { isa = PBXGroup; children = ( - 5D506B5639A1D45519536773 /* libPods-LFLiveKitDemo.a */, + 5B1CCEEE06FCFAF75D105A51 /* libPods-LFLiveKitDemo.a */, ); name = Frameworks; sourceTree = ""; }; - 840762E31D07C7D0000FD0BF = { + 84D8B41D1D75778B00752B56 = { isa = PBXGroup; children = ( - 840762EE1D07C7D0000FD0BF /* LFLiveKitDemo */, - 840763081D07C7D0000FD0BF /* LFLiveKitDemoTests */, - 840763131D07C7D0000FD0BF /* LFLiveKitDemoUITests */, - 840762ED1D07C7D0000FD0BF /* Products */, - 9BA1F10CECEAF692D0035AED /* Pods */, - 713DA9EBCA308093C74917F9 /* Frameworks */, + 84D8B4CE1D757F0700752B56 /* libstdc++.tbd */, + 84D8B4281D75778B00752B56 /* LFLiveKitDemo */, + 84D8B4271D75778B00752B56 /* Products */, + F3E359B8A7561F963C47A62F /* Pods */, + 65E0CF98FF954863E543A0E1 /* Frameworks */, ); sourceTree = ""; }; - 840762ED1D07C7D0000FD0BF /* Products */ = { + 84D8B4271D75778B00752B56 /* Products */ = { isa = PBXGroup; children = ( - 840762EC1D07C7D0000FD0BF /* LFLiveKitDemo.app */, + 84D8B4261D75778B00752B56 /* LFLiveKitDemo.app */, ); name = Products; sourceTree = ""; }; - 840762EE1D07C7D0000FD0BF /* LFLiveKitDemo */ = { + 84D8B4281D75778B00752B56 /* LFLiveKitDemo */ = { isa = PBXGroup; children = ( - 840763221D07C894000FD0BF /* category */, - 840763271D07C894000FD0BF /* LFLivePreview.h */, - 840763281D07C894000FD0BF /* LFLivePreview.m */, - 840762F21D07C7D0000FD0BF /* AppDelegate.h */, - 840762F31D07C7D0000FD0BF /* AppDelegate.m */, - 840762F51D07C7D0000FD0BF /* ViewController.h */, - 840762F61D07C7D0000FD0BF /* ViewController.m */, - 840762F81D07C7D0000FD0BF /* Main.storyboard */, - 840762FB1D07C7D0000FD0BF /* Assets.xcassets */, - 840762FD1D07C7D0000FD0BF /* LaunchScreen.storyboard */, - 840763001D07C7D0000FD0BF /* Info.plist */, - 840762EF1D07C7D0000FD0BF /* Supporting Files */, + 84D8B42C1D75778B00752B56 /* AppDelegate.h */, + 84D8B42D1D75778B00752B56 /* AppDelegate.m */, + 84D8B42F1D75778B00752B56 /* ViewController.h */, + 84D8B4301D75778B00752B56 /* ViewController.m */, + 84D8B4491D75781200752B56 /* LFLivePreview.h */, + 84D8B44A1D75781200752B56 /* LFLivePreview.m */, + 84D8B44C1D75782700752B56 /* category */, + 84D8B4511D75782700752B56 /* images */, + 84D8B4321D75778B00752B56 /* Main.storyboard */, + 84D8B4351D75778B00752B56 /* Assets.xcassets */, + 84D8B4371D75778B00752B56 /* LaunchScreen.storyboard */, + 84D8B43A1D75778B00752B56 /* Info.plist */, + 84D8B4291D75778B00752B56 /* Supporting Files */, ); path = LFLiveKitDemo; sourceTree = ""; }; - 840762EF1D07C7D0000FD0BF /* Supporting Files */ = { + 84D8B4291D75778B00752B56 /* Supporting Files */ = { isa = PBXGroup; children = ( - 8407632C1D07C899000FD0BF /* images */, - 840762F01D07C7D0000FD0BF /* main.m */, + 84D8B42A1D75778B00752B56 /* main.m */, ); name = "Supporting Files"; sourceTree = ""; }; - 840763081D07C7D0000FD0BF /* LFLiveKitDemoTests */ = { + 84D8B44C1D75782700752B56 /* category */ = { isa = PBXGroup; children = ( - 840763091D07C7D0000FD0BF /* LFLiveKitDemoTests.m */, - 8407630B1D07C7D0000FD0BF /* Info.plist */, - ); - path = LFLiveKitDemoTests; - sourceTree = ""; - }; - 840763131D07C7D0000FD0BF /* LFLiveKitDemoUITests */ = { - isa = PBXGroup; - children = ( - 840763141D07C7D0000FD0BF /* LFLiveKitDemoUITests.m */, - 840763161D07C7D0000FD0BF /* Info.plist */, - ); - path = LFLiveKitDemoUITests; - sourceTree = ""; - }; - 840763221D07C894000FD0BF /* category */ = { - isa = PBXGroup; - children = ( - 840763231D07C894000FD0BF /* UIControl+YYAdd.h */, - 840763241D07C894000FD0BF /* UIControl+YYAdd.m */, - 840763251D07C894000FD0BF /* UIView+YYAdd.h */, - 840763261D07C894000FD0BF /* UIView+YYAdd.m */, + 84D8B44D1D75782700752B56 /* UIControl+YYAdd.h */, + 84D8B44E1D75782700752B56 /* UIControl+YYAdd.m */, + 84D8B44F1D75782700752B56 /* UIView+YYAdd.h */, + 84D8B4501D75782700752B56 /* UIView+YYAdd.m */, ); path = category; sourceTree = ""; }; - 8407632C1D07C899000FD0BF /* images */ = { + 84D8B4511D75782700752B56 /* images */ = { isa = PBXGroup; children = ( - 8407632D1D07C899000FD0BF /* camra_beauty@2x.png */, - 8407632E1D07C899000FD0BF /* camra_beauty@3x.png */, - 8407632F1D07C899000FD0BF /* camra_beauty_close@2x.png */, - 840763301D07C899000FD0BF /* camra_beauty_close@3x.png */, - 840763311D07C899000FD0BF /* camra_preview@2x.png */, - 840763321D07C899000FD0BF /* camra_preview@3x.png */, - 840763331D07C899000FD0BF /* close_preview@2x.png */, - 840763341D07C899000FD0BF /* close_preview@3x.png */, + 84D8B4521D75782700752B56 /* camra_beauty@2x.png */, + 84D8B4531D75782700752B56 /* camra_beauty@3x.png */, + 84D8B4541D75782700752B56 /* camra_beauty_close@2x.png */, + 84D8B4551D75782700752B56 /* camra_beauty_close@3x.png */, + 84D8B4561D75782700752B56 /* camra_preview@2x.png */, + 84D8B4571D75782700752B56 /* camra_preview@3x.png */, + 84D8B4581D75782700752B56 /* close_preview@2x.png */, + 84D8B4591D75782700752B56 /* close_preview@3x.png */, + 84D8B45A1D75782700752B56 /* ios-29x29.png */, ); path = images; sourceTree = ""; }; - 9BA1F10CECEAF692D0035AED /* Pods */ = { + F3E359B8A7561F963C47A62F /* Pods */ = { isa = PBXGroup; children = ( - 7FAA55DD93CD7AB58E7A977A /* Pods-LFLiveKitDemo.debug.xcconfig */, - 195672426061368F86F1F4FA /* Pods-LFLiveKitDemo.release.xcconfig */, + 289A9C4510CD7EA6F4CE9897 /* Pods-LFLiveKitDemo.debug.xcconfig */, + 96E1231310083A3881AD2AB6 /* Pods-LFLiveKitDemo.release.xcconfig */, ); name = Pods; sourceTree = ""; @@ -185,16 +168,16 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ - 840762EB1D07C7D0000FD0BF /* LFLiveKitDemo */ = { + 84D8B4251D75778B00752B56 /* LFLiveKitDemo */ = { isa = PBXNativeTarget; - buildConfigurationList = 840763191D07C7D0000FD0BF /* Build configuration list for PBXNativeTarget "LFLiveKitDemo" */; + buildConfigurationList = 84D8B43D1D75778B00752B56 /* Build configuration list for PBXNativeTarget "LFLiveKitDemo" */; buildPhases = ( - 7E4C7C5523618A0595228010 /* 📦 Check Pods Manifest.lock */, - 840762E81D07C7D0000FD0BF /* Sources */, - 840762E91D07C7D0000FD0BF /* Frameworks */, - 840762EA1D07C7D0000FD0BF /* Resources */, - E4007BB7D4B0E165011BF22F /* 📦 Embed Pods Frameworks */, - 64FCFF97E6544B1C8F282394 /* 📦 Copy Pods Resources */, + A819C09CC049A57DC5C97E12 /* 📦 Check Pods Manifest.lock */, + 84D8B4221D75778B00752B56 /* Sources */, + 84D8B4231D75778B00752B56 /* Frameworks */, + 84D8B4241D75778B00752B56 /* Resources */, + 883533331BE4DCC0DB5075CF /* 📦 Embed Pods Frameworks */, + 4CC4C37B93D109913E475307 /* 📦 Copy Pods Resources */, ); buildRules = ( ); @@ -202,24 +185,25 @@ ); name = LFLiveKitDemo; productName = LFLiveKitDemo; - productReference = 840762EC1D07C7D0000FD0BF /* LFLiveKitDemo.app */; + productReference = 84D8B4261D75778B00752B56 /* LFLiveKitDemo.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ - 840762E41D07C7D0000FD0BF /* Project object */ = { + 84D8B41E1D75778B00752B56 /* Project object */ = { isa = PBXProject; attributes = { LastUpgradeCheck = 0730; ORGANIZATIONNAME = admin; TargetAttributes = { - 840762EB1D07C7D0000FD0BF = { - CreatedOnToolsVersion = 7.3; + 84D8B4251D75778B00752B56 = { + CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = G497YX6CBT; }; }; }; - buildConfigurationList = 840762E71D07C7D0000FD0BF /* Build configuration list for PBXProject "LFLiveKitDemo" */; + buildConfigurationList = 84D8B4211D75778B00752B56 /* Build configuration list for PBXProject "LFLiveKitDemo" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; @@ -227,39 +211,40 @@ en, Base, ); - mainGroup = 840762E31D07C7D0000FD0BF; - productRefGroup = 840762ED1D07C7D0000FD0BF /* Products */; + mainGroup = 84D8B41D1D75778B00752B56; + productRefGroup = 84D8B4271D75778B00752B56 /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( - 840762EB1D07C7D0000FD0BF /* LFLiveKitDemo */, + 84D8B4251D75778B00752B56 /* LFLiveKitDemo */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ - 840762EA1D07C7D0000FD0BF /* Resources */ = { + 84D8B4241D75778B00752B56 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 840763371D07C899000FD0BF /* camra_beauty_close@2x.png in Resources */, - 840762FF1D07C7D0000FD0BF /* LaunchScreen.storyboard in Resources */, - 840763351D07C899000FD0BF /* camra_beauty@2x.png in Resources */, - 840762FC1D07C7D0000FD0BF /* Assets.xcassets in Resources */, - 8407633A1D07C899000FD0BF /* camra_preview@3x.png in Resources */, - 840763381D07C899000FD0BF /* camra_beauty_close@3x.png in Resources */, - 8407633C1D07C899000FD0BF /* close_preview@3x.png in Resources */, - 8407633B1D07C899000FD0BF /* close_preview@2x.png in Resources */, - 840762FA1D07C7D0000FD0BF /* Main.storyboard in Resources */, - 840763391D07C899000FD0BF /* camra_preview@2x.png in Resources */, - 840763361D07C899000FD0BF /* camra_beauty@3x.png in Resources */, + 84D8B45F1D75782700752B56 /* camra_beauty_close@2x.png in Resources */, + 84D8B4391D75778B00752B56 /* LaunchScreen.storyboard in Resources */, + 84D8B45D1D75782700752B56 /* camra_beauty@2x.png in Resources */, + 84D8B4361D75778B00752B56 /* Assets.xcassets in Resources */, + 84D8B4621D75782700752B56 /* camra_preview@3x.png in Resources */, + 84D8B4601D75782700752B56 /* camra_beauty_close@3x.png in Resources */, + 84D8B4651D75782700752B56 /* ios-29x29.png in Resources */, + 84D8B4641D75782700752B56 /* close_preview@3x.png in Resources */, + 84D8B4631D75782700752B56 /* close_preview@2x.png in Resources */, + 84D8B4341D75778B00752B56 /* Main.storyboard in Resources */, + 84D8B4611D75782700752B56 /* camra_preview@2x.png in Resources */, + 84D8B45E1D75782700752B56 /* camra_beauty@3x.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 64FCFF97E6544B1C8F282394 /* 📦 Copy Pods Resources */ = { + 4CC4C37B93D109913E475307 /* 📦 Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -274,67 +259,67 @@ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LFLiveKitDemo/Pods-LFLiveKitDemo-resources.sh\"\n"; showEnvVarsInLog = 0; }; - 7E4C7C5523618A0595228010 /* 📦 Check Pods Manifest.lock */ = { + 883533331BE4DCC0DB5075CF /* 📦 Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "📦 Check Pods Manifest.lock"; + name = "📦 Embed Pods Frameworks"; 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"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LFLiveKitDemo/Pods-LFLiveKitDemo-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - E4007BB7D4B0E165011BF22F /* 📦 Embed Pods Frameworks */ = { + A819C09CC049A57DC5C97E12 /* 📦 Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "📦 Embed Pods Frameworks"; + name = "📦 Check Pods Manifest.lock"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LFLiveKitDemo/Pods-LFLiveKitDemo-frameworks.sh\"\n"; + 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 */ - 840762E81D07C7D0000FD0BF /* Sources */ = { + 84D8B4221D75778B00752B56 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8407632B1D07C894000FD0BF /* LFLivePreview.m in Sources */, - 840762F71D07C7D0000FD0BF /* ViewController.m in Sources */, - 840763291D07C894000FD0BF /* UIControl+YYAdd.m in Sources */, - 840762F41D07C7D0000FD0BF /* AppDelegate.m in Sources */, - 8407632A1D07C894000FD0BF /* UIView+YYAdd.m in Sources */, - 840762F11D07C7D0000FD0BF /* main.m in Sources */, + 84D8B45B1D75782700752B56 /* UIControl+YYAdd.m in Sources */, + 84D8B4311D75778B00752B56 /* ViewController.m in Sources */, + 84D8B45C1D75782700752B56 /* UIView+YYAdd.m in Sources */, + 84D8B42E1D75778B00752B56 /* AppDelegate.m in Sources */, + 84D8B44B1D75781200752B56 /* LFLivePreview.m in Sources */, + 84D8B42B1D75778B00752B56 /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ - 840762F81D07C7D0000FD0BF /* Main.storyboard */ = { + 84D8B4321D75778B00752B56 /* Main.storyboard */ = { isa = PBXVariantGroup; children = ( - 840762F91D07C7D0000FD0BF /* Base */, + 84D8B4331D75778B00752B56 /* Base */, ); name = Main.storyboard; sourceTree = ""; }; - 840762FD1D07C7D0000FD0BF /* LaunchScreen.storyboard */ = { + 84D8B4371D75778B00752B56 /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( - 840762FE1D07C7D0000FD0BF /* Base */, + 84D8B4381D75778B00752B56 /* Base */, ); name = LaunchScreen.storyboard; sourceTree = ""; @@ -342,7 +327,7 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ - 840763171D07C7D0000FD0BF /* Debug */ = { + 84D8B43B1D75778B00752B56 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; @@ -379,15 +364,14 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; - 840763181D07C7D0000FD0BF /* Release */ = { + 84D8B43C1D75778B00752B56 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; @@ -418,38 +402,45 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; name = Release; }; - 8407631A1D07C7D0000FD0BF /* Debug */ = { + 84D8B43E1D75778B00752B56 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7FAA55DD93CD7AB58E7A977A /* Pods-LFLiveKitDemo.debug.xcconfig */; + baseConfigurationReference = 289A9C4510CD7EA6F4CE9897 /* Pods-LFLiveKitDemo.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - ENABLE_BITCODE = NO; + DEVELOPMENT_TEAM = G497YX6CBT; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + HEADER_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = LFLiveKitDemo/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKit.LFLiveKitDemo; + LIBRARY_SEARCH_PATHS = "$(inherited)"; + OTHER_LDFLAGS = "$(inherited)"; + PRODUCT_BUNDLE_IDENTIFIER = com.youku.LaiFeng; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; }; - 8407631B1D07C7D0000FD0BF /* Release */ = { + 84D8B43F1D75778B00752B56 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 195672426061368F86F1F4FA /* Pods-LFLiveKitDemo.release.xcconfig */; + baseConfigurationReference = 96E1231310083A3881AD2AB6 /* Pods-LFLiveKitDemo.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - ENABLE_BITCODE = NO; + DEVELOPMENT_TEAM = G497YX6CBT; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + HEADER_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = LFLiveKitDemo/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKit.LFLiveKitDemo; + LIBRARY_SEARCH_PATHS = "$(inherited)"; + OTHER_LDFLAGS = "$(inherited)"; + PRODUCT_BUNDLE_IDENTIFIER = com.youku.LaiFeng; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -457,25 +448,25 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 840762E71D07C7D0000FD0BF /* Build configuration list for PBXProject "LFLiveKitDemo" */ = { + 84D8B4211D75778B00752B56 /* Build configuration list for PBXProject "LFLiveKitDemo" */ = { isa = XCConfigurationList; buildConfigurations = ( - 840763171D07C7D0000FD0BF /* Debug */, - 840763181D07C7D0000FD0BF /* Release */, + 84D8B43B1D75778B00752B56 /* Debug */, + 84D8B43C1D75778B00752B56 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 840763191D07C7D0000FD0BF /* Build configuration list for PBXNativeTarget "LFLiveKitDemo" */ = { + 84D8B43D1D75778B00752B56 /* Build configuration list for PBXNativeTarget "LFLiveKitDemo" */ = { isa = XCConfigurationList; buildConfigurations = ( - 8407631A1D07C7D0000FD0BF /* Debug */, - 8407631B1D07C7D0000FD0BF /* Release */, + 84D8B43E1D75778B00752B56 /* Debug */, + 84D8B43F1D75778B00752B56 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; - rootObject = 840762E41D07C7D0000FD0BF /* Project object */; + rootObject = 84D8B41E1D75778B00752B56 /* Project object */; } diff --git a/LFLiveKitDemo/LFLiveKitDemo/AppDelegate.h b/samples/LFLiveKitDemo/LFLiveKitDemo/AppDelegate.h similarity index 88% rename from LFLiveKitDemo/LFLiveKitDemo/AppDelegate.h rename to samples/LFLiveKitDemo/LFLiveKitDemo/AppDelegate.h index d189e69e..1695b906 100644 --- a/LFLiveKitDemo/LFLiveKitDemo/AppDelegate.h +++ b/samples/LFLiveKitDemo/LFLiveKitDemo/AppDelegate.h @@ -2,7 +2,7 @@ // AppDelegate.h // LFLiveKitDemo // -// Created by admin on 16/6/8. +// Created by admin on 16/8/30. // Copyright © 2016年 admin. All rights reserved. // diff --git a/LFLiveKitDemo/LFLiveKitDemo/AppDelegate.m b/samples/LFLiveKitDemo/LFLiveKitDemo/AppDelegate.m similarity index 98% rename from LFLiveKitDemo/LFLiveKitDemo/AppDelegate.m rename to samples/LFLiveKitDemo/LFLiveKitDemo/AppDelegate.m index 1ffb3826..1b9c0098 100644 --- a/LFLiveKitDemo/LFLiveKitDemo/AppDelegate.m +++ b/samples/LFLiveKitDemo/LFLiveKitDemo/AppDelegate.m @@ -2,7 +2,7 @@ // AppDelegate.m // LFLiveKitDemo // -// Created by admin on 16/6/8. +// Created by admin on 16/8/30. // Copyright © 2016年 admin. All rights reserved. // diff --git a/LFLiveKitDemo/LFLiveKitDemo/Assets.xcassets/AppIcon.appiconset/Contents.json b/samples/LFLiveKitDemo/LFLiveKitDemo/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 54% rename from LFLiveKitDemo/LFLiveKitDemo/Assets.xcassets/AppIcon.appiconset/Contents.json rename to samples/LFLiveKitDemo/LFLiveKitDemo/Assets.xcassets/AppIcon.appiconset/Contents.json index 36d2c80d..118c98f7 100644 --- a/LFLiveKitDemo/LFLiveKitDemo/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/samples/LFLiveKitDemo/LFLiveKitDemo/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -29,36 +29,6 @@ "idiom" : "iphone", "size" : "60x60", "scale" : "3x" - }, - { - "idiom" : "ipad", - "size" : "29x29", - "scale" : "1x" - }, - { - "idiom" : "ipad", - "size" : "29x29", - "scale" : "2x" - }, - { - "idiom" : "ipad", - "size" : "40x40", - "scale" : "1x" - }, - { - "idiom" : "ipad", - "size" : "40x40", - "scale" : "2x" - }, - { - "idiom" : "ipad", - "size" : "76x76", - "scale" : "1x" - }, - { - "idiom" : "ipad", - "size" : "76x76", - "scale" : "2x" } ], "info" : { diff --git a/LFLiveKitDemo/LFLiveKitDemo/Base.lproj/LaunchScreen.storyboard b/samples/LFLiveKitDemo/LFLiveKitDemo/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from LFLiveKitDemo/LFLiveKitDemo/Base.lproj/LaunchScreen.storyboard rename to samples/LFLiveKitDemo/LFLiveKitDemo/Base.lproj/LaunchScreen.storyboard diff --git a/LFLiveKitDemo/LFLiveKitDemo/Base.lproj/Main.storyboard b/samples/LFLiveKitDemo/LFLiveKitDemo/Base.lproj/Main.storyboard similarity index 100% rename from LFLiveKitDemo/LFLiveKitDemo/Base.lproj/Main.storyboard rename to samples/LFLiveKitDemo/LFLiveKitDemo/Base.lproj/Main.storyboard diff --git a/samples/LFLiveKitDemo/LFLiveKitDemo/Info.plist b/samples/LFLiveKitDemo/LFLiveKitDemo/Info.plist new file mode 100644 index 00000000..a44da8ce --- /dev/null +++ b/samples/LFLiveKitDemo/LFLiveKitDemo/Info.plist @@ -0,0 +1,43 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + NSCameraUsageDescription + cameraDesciption + NSMicrophoneUsageDescription + microphoneDesciption + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/LFLiveKitDemo/LFLiveKitDemo/LFLivePreview.h b/samples/LFLiveKitDemo/LFLiveKitDemo/LFLivePreview.h similarity index 99% rename from LFLiveKitDemo/LFLiveKitDemo/LFLivePreview.h rename to samples/LFLiveKitDemo/LFLiveKitDemo/LFLivePreview.h index 096b8d46..14a93625 100755 --- a/LFLiveKitDemo/LFLiveKitDemo/LFLivePreview.h +++ b/samples/LFLiveKitDemo/LFLiveKitDemo/LFLivePreview.h @@ -10,5 +10,4 @@ @interface LFLivePreview : UIView - @end diff --git a/samples/LFLiveKitDemo/LFLiveKitDemo/LFLivePreview.m b/samples/LFLiveKitDemo/LFLiveKitDemo/LFLivePreview.m new file mode 100755 index 00000000..1ebf6a22 --- /dev/null +++ b/samples/LFLiveKitDemo/LFLiveKitDemo/LFLivePreview.m @@ -0,0 +1,374 @@ +// +// LFLivePreview.m +// LFLiveKit +// +// Created by 倾慕 on 16/5/2. +// Copyright © 2016年 live Interactive. All rights reserved. +// + +#import "LFLivePreview.h" +#import "UIControl+YYAdd.h" +#import "UIView+YYAdd.h" +#import "LFLiveKit.h" + +inline static NSString *formatedSpeed(float bytes, float elapsed_milli) { + if (elapsed_milli <= 0) { + return @"N/A"; + } + + if (bytes <= 0) { + return @"0 KB/s"; + } + + float bytes_per_sec = ((float)bytes) * 1000.f / elapsed_milli; + if (bytes_per_sec >= 1000 * 1000) { + return [NSString stringWithFormat:@"%.2f MB/s", ((float)bytes_per_sec) / 1000 / 1000]; + } else if (bytes_per_sec >= 1000) { + return [NSString stringWithFormat:@"%.1f KB/s", ((float)bytes_per_sec) / 1000]; + } else { + return [NSString stringWithFormat:@"%ld B/s", (long)bytes_per_sec]; + } +} + +@interface LFLivePreview () + +@property (nonatomic, strong) UIButton *beautyButton; +@property (nonatomic, strong) UIButton *cameraButton; +@property (nonatomic, strong) UIButton *closeButton; +@property (nonatomic, strong) UIButton *startLiveButton; +@property (nonatomic, strong) UIView *containerView; +@property (nonatomic, strong) LFLiveDebug *debugInfo; +@property (nonatomic, strong) LFLiveSession *session; +@property (nonatomic, strong) UILabel *stateLabel; + +@end + +@implementation LFLivePreview + +- (instancetype)initWithFrame:(CGRect)frame { + if (self = [super initWithFrame:frame]) { + self.backgroundColor = [UIColor clearColor]; + [self requestAccessForVideo]; + [self requestAccessForAudio]; + [self addSubview:self.containerView]; + [self.containerView addSubview:self.stateLabel]; + [self.containerView addSubview:self.closeButton]; + [self.containerView addSubview:self.cameraButton]; + [self.containerView addSubview:self.beautyButton]; + [self.containerView addSubview:self.startLiveButton]; + } + return self; +} + +#pragma mark -- Public Method +- (void)requestAccessForVideo { + __weak typeof(self) _self = self; + AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; + switch (status) { + case AVAuthorizationStatusNotDetermined: { + // 许可对话没有出现,发起授权许可 + [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { + if (granted) { + dispatch_async(dispatch_get_main_queue(), ^{ + [_self.session setRunning:YES]; + }); + } + }]; + break; + } + case AVAuthorizationStatusAuthorized: { + // 已经开启授权,可继续 + dispatch_async(dispatch_get_main_queue(), ^{ + [_self.session setRunning:YES]; + }); + break; + } + case AVAuthorizationStatusDenied: + case AVAuthorizationStatusRestricted: + // 用户明确地拒绝授权,或者相机设备无法访问 + + break; + default: + break; + } +} + +- (void)requestAccessForAudio { + AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]; + switch (status) { + case AVAuthorizationStatusNotDetermined: { + [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) { + }]; + break; + } + case AVAuthorizationStatusAuthorized: { + break; + } + case AVAuthorizationStatusDenied: + case AVAuthorizationStatusRestricted: + break; + default: + break; + } +} + +#pragma mark -- LFStreamingSessionDelegate +/** live status changed will callback */ +- (void)liveSession:(nullable LFLiveSession *)session liveStateDidChange:(LFLiveState)state { + NSLog(@"liveStateDidChange: %ld", state); + switch (state) { + case LFLiveReady: + _stateLabel.text = @"未连接"; + break; + case LFLivePending: + _stateLabel.text = @"连接中"; + break; + case LFLiveStart: + _stateLabel.text = @"已连接"; + break; + case LFLiveError: + _stateLabel.text = @"连接错误"; + break; + case LFLiveStop: + _stateLabel.text = @"未连接"; + break; + default: + break; + } +} + +/** live debug info callback */ +- (void)liveSession:(nullable LFLiveSession *)session debugInfo:(nullable LFLiveDebug *)debugInfo { + NSLog(@"debugInfo uploadSpeed: %@", formatedSpeed(debugInfo.currentBandwidth, debugInfo.elapsedMilli)); +} + +/** callback socket errorcode */ +- (void)liveSession:(nullable LFLiveSession *)session errorCode:(LFLiveSocketErrorCode)errorCode { + NSLog(@"errorCode: %ld", errorCode); +} + +#pragma mark -- Getter Setter +- (LFLiveSession *)session { + if (!_session) { + /** 发现大家有不会用横屏的请注意啦,横屏需要在ViewController supportedInterfaceOrientations修改方向 默认竖屏 ****/ + /** 发现大家有不会用横屏的请注意啦,横屏需要在ViewController supportedInterfaceOrientations修改方向 默认竖屏 ****/ + /** 发现大家有不会用横屏的请注意啦,横屏需要在ViewController supportedInterfaceOrientations修改方向 默认竖屏 ****/ + + + /***  默认分辨率368 * 640 音频:44.1 iphone6以上48 双声道 方向竖屏 ***/ + LFLiveVideoConfiguration *videoConfiguration = [LFLiveVideoConfiguration new]; + videoConfiguration.videoSize = CGSizeMake(640, 360); + videoConfiguration.videoBitRate = 800*1024; + videoConfiguration.videoMaxBitRate = 1000*1024; + videoConfiguration.videoMinBitRate = 500*1024; + videoConfiguration.videoFrameRate = 24; + videoConfiguration.videoMaxKeyframeInterval = 48; + videoConfiguration.outputImageOrientation = UIInterfaceOrientationLandscapeLeft; + videoConfiguration.autorotate = NO; + videoConfiguration.sessionPreset = LFCaptureSessionPreset720x1280; + _session = [[LFLiveSession alloc] initWithAudioConfiguration:[LFLiveAudioConfiguration defaultConfiguration] videoConfiguration:videoConfiguration captureType:LFLiveCaptureDefaultMask]; + + /**   自己定制单声道 */ + /* + LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; + audioConfiguration.numberOfChannels = 1; + audioConfiguration.audioBitrate = LFLiveAudioBitRate_64Kbps; + audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; + _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:[LFLiveVideoConfiguration defaultConfiguration]]; + */ + + /**   自己定制高质量音频96K */ + /* + LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; + audioConfiguration.numberOfChannels = 2; + audioConfiguration.audioBitrate = LFLiveAudioBitRate_96Kbps; + audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; + _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:[LFLiveVideoConfiguration defaultConfiguration]]; + */ + + /**   自己定制高质量音频96K 分辨率设置为540*960 方向竖屏 */ + + /* + LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; + audioConfiguration.numberOfChannels = 2; + audioConfiguration.audioBitrate = LFLiveAudioBitRate_96Kbps; + audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; + + LFLiveVideoConfiguration *videoConfiguration = [LFLiveVideoConfiguration new]; + videoConfiguration.videoSize = CGSizeMake(540, 960); + videoConfiguration.videoBitRate = 800*1024; + videoConfiguration.videoMaxBitRate = 1000*1024; + videoConfiguration.videoMinBitRate = 500*1024; + videoConfiguration.videoFrameRate = 24; + videoConfiguration.videoMaxKeyframeInterval = 48; + videoConfiguration.orientation = UIInterfaceOrientationPortrait; + videoConfiguration.sessionPreset = LFCaptureSessionPreset540x960; + + _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:videoConfiguration]; + */ + + + /**   自己定制高质量音频128K 分辨率设置为720*1280 方向竖屏 */ + + /* + LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; + audioConfiguration.numberOfChannels = 2; + audioConfiguration.audioBitrate = LFLiveAudioBitRate_128Kbps; + audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; + + LFLiveVideoConfiguration *videoConfiguration = [LFLiveVideoConfiguration new]; + videoConfiguration.videoSize = CGSizeMake(720, 1280); + videoConfiguration.videoBitRate = 800*1024; + videoConfiguration.videoMaxBitRate = 1000*1024; + videoConfiguration.videoMinBitRate = 500*1024; + videoConfiguration.videoFrameRate = 15; + videoConfiguration.videoMaxKeyframeInterval = 30; + videoConfiguration.landscape = NO; + videoConfiguration.sessionPreset = LFCaptureSessionPreset360x640; + + _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:videoConfiguration]; + */ + + + /**   自己定制高质量音频128K 分辨率设置为720*1280 方向横屏 */ + + /* + LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; + audioConfiguration.numberOfChannels = 2; + audioConfiguration.audioBitrate = LFLiveAudioBitRate_128Kbps; + audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; + + LFLiveVideoConfiguration *videoConfiguration = [LFLiveVideoConfiguration new]; + videoConfiguration.videoSize = CGSizeMake(1280, 720); + videoConfiguration.videoBitRate = 800*1024; + videoConfiguration.videoMaxBitRate = 1000*1024; + videoConfiguration.videoMinBitRate = 500*1024; + videoConfiguration.videoFrameRate = 15; + videoConfiguration.videoMaxKeyframeInterval = 30; + videoConfiguration.landscape = YES; + videoConfiguration.sessionPreset = LFCaptureSessionPreset720x1280; + + _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:videoConfiguration]; + */ + + _session.delegate = self; + _session.showDebugInfo = NO; + _session.preView = self; + + /*本地存储*/ +// _session.saveLocalVideo = YES; +// NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.mp4"]; +// unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie +// NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie]; +// _session.saveLocalVideoPath = movieURL; + + /* + UIImageView *imageView = [[UIImageView alloc] init]; + imageView.alpha = 0.8; + imageView.frame = CGRectMake(100, 100, 29, 29); + imageView.image = [UIImage imageNamed:@"ios-29x29"]; + _session.warterMarkView = imageView;*/ + + } + return _session; +} + +- (UIView *)containerView { + if (!_containerView) { + _containerView = [UIView new]; + _containerView.frame = self.bounds; + _containerView.backgroundColor = [UIColor clearColor]; + _containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + } + return _containerView; +} + +- (UILabel *)stateLabel { + if (!_stateLabel) { + _stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 80, 40)]; + _stateLabel.text = @"未连接"; + _stateLabel.textColor = [UIColor whiteColor]; + _stateLabel.font = [UIFont boldSystemFontOfSize:14.f]; + } + return _stateLabel; +} + +- (UIButton *)closeButton { + if (!_closeButton) { + _closeButton = [UIButton new]; + _closeButton.size = CGSizeMake(44, 44); + _closeButton.left = self.width - 10 - _closeButton.width; + _closeButton.top = 20; + [_closeButton setImage:[UIImage imageNamed:@"close_preview"] forState:UIControlStateNormal]; + _closeButton.exclusiveTouch = YES; + [_closeButton addBlockForControlEvents:UIControlEventTouchUpInside block:^(id sender) { + + }]; + } + return _closeButton; +} + +- (UIButton *)cameraButton { + if (!_cameraButton) { + _cameraButton = [UIButton new]; + _cameraButton.size = CGSizeMake(44, 44); + _cameraButton.origin = CGPointMake(_closeButton.left - 10 - _cameraButton.width, 20); + [_cameraButton setImage:[UIImage imageNamed:@"camra_preview"] forState:UIControlStateNormal]; + _cameraButton.exclusiveTouch = YES; + __weak typeof(self) _self = self; + [_cameraButton addBlockForControlEvents:UIControlEventTouchUpInside block:^(id sender) { + AVCaptureDevicePosition devicePositon = _self.session.captureDevicePosition; + _self.session.captureDevicePosition = (devicePositon == AVCaptureDevicePositionBack) ? AVCaptureDevicePositionFront : AVCaptureDevicePositionBack; + }]; + } + return _cameraButton; +} + +- (UIButton *)beautyButton { + if (!_beautyButton) { + _beautyButton = [UIButton new]; + _beautyButton.size = CGSizeMake(44, 44); + _beautyButton.origin = CGPointMake(_cameraButton.left - 10 - _beautyButton.width, 20); + [_beautyButton setImage:[UIImage imageNamed:@"camra_beauty"] forState:UIControlStateNormal]; + [_beautyButton setImage:[UIImage imageNamed:@"camra_beauty_close"] forState:UIControlStateSelected]; + _beautyButton.exclusiveTouch = YES; + __weak typeof(self) _self = self; + [_beautyButton addBlockForControlEvents:UIControlEventTouchUpInside block:^(id sender) { + _self.session.beautyFace = !_self.session.beautyFace; + _self.beautyButton.selected = !_self.session.beautyFace; + }]; + } + return _beautyButton; +} + +- (UIButton *)startLiveButton { + if (!_startLiveButton) { + _startLiveButton = [UIButton new]; + _startLiveButton.size = CGSizeMake(self.width - 60, 44); + _startLiveButton.left = 30; + _startLiveButton.bottom = self.height - 50; + _startLiveButton.layer.cornerRadius = _startLiveButton.height/2; + [_startLiveButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; + [_startLiveButton.titleLabel setFont:[UIFont systemFontOfSize:16]]; + [_startLiveButton setTitle:@"开始直播" forState:UIControlStateNormal]; + [_startLiveButton setBackgroundColor:[UIColor colorWithRed:50 green:32 blue:245 alpha:1]]; + _startLiveButton.exclusiveTouch = YES; + __weak typeof(self) _self = self; + [_startLiveButton addBlockForControlEvents:UIControlEventTouchUpInside block:^(id sender) { + _self.startLiveButton.selected = !_self.startLiveButton.selected; + if (_self.startLiveButton.selected) { + [_self.startLiveButton setTitle:@"结束直播" forState:UIControlStateNormal]; + LFLiveStreamInfo *stream = [LFLiveStreamInfo new]; + stream.url = @"rtmp://live.hkstv.hk.lxdns.com:1935/live/stream153"; + [_self.session startLive:stream]; + } else { + [_self.startLiveButton setTitle:@"开始直播" forState:UIControlStateNormal]; + [_self.session stopLive]; + } + }]; + } + return _startLiveButton; +} + +@end + diff --git a/LFLiveKitDemo/LFLiveKitDemo/ViewController.h b/samples/LFLiveKitDemo/LFLiveKitDemo/ViewController.h similarity index 84% rename from LFLiveKitDemo/LFLiveKitDemo/ViewController.h rename to samples/LFLiveKitDemo/LFLiveKitDemo/ViewController.h index 3f05eca3..17cbf1f5 100644 --- a/LFLiveKitDemo/LFLiveKitDemo/ViewController.h +++ b/samples/LFLiveKitDemo/LFLiveKitDemo/ViewController.h @@ -2,7 +2,7 @@ // ViewController.h // LFLiveKitDemo // -// Created by admin on 16/6/8. +// Created by admin on 16/8/30. // Copyright © 2016年 admin. All rights reserved. // diff --git a/samples/LFLiveKitDemo/LFLiveKitDemo/ViewController.m b/samples/LFLiveKitDemo/LFLiveKitDemo/ViewController.m new file mode 100644 index 00000000..550ed937 --- /dev/null +++ b/samples/LFLiveKitDemo/LFLiveKitDemo/ViewController.m @@ -0,0 +1,32 @@ +// +// ViewController.m +// LFLiveKitDemo +// +// Created by admin on 16/8/30. +// Copyright © 2016年 admin. All rights reserved. +// + +#import "ViewController.h" +#import "LFLivePreview.h" + +@interface ViewController () + +@end + +@implementation ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view, typically from a nib. + [self.view addSubview:[[LFLivePreview alloc] initWithFrame:self.view.bounds]]; +} + +- (UIInterfaceOrientationMask)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskLandscape; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { + return YES; +} + +@end diff --git a/LFLiveKitDemo/LFLiveKitDemo/category/UIControl+YYAdd.h b/samples/LFLiveKitDemo/LFLiveKitDemo/category/UIControl+YYAdd.h similarity index 100% rename from LFLiveKitDemo/LFLiveKitDemo/category/UIControl+YYAdd.h rename to samples/LFLiveKitDemo/LFLiveKitDemo/category/UIControl+YYAdd.h diff --git a/LFLiveKitDemo/LFLiveKitDemo/category/UIControl+YYAdd.m b/samples/LFLiveKitDemo/LFLiveKitDemo/category/UIControl+YYAdd.m similarity index 100% rename from LFLiveKitDemo/LFLiveKitDemo/category/UIControl+YYAdd.m rename to samples/LFLiveKitDemo/LFLiveKitDemo/category/UIControl+YYAdd.m diff --git a/LFLiveKitDemo/LFLiveKitDemo/category/UIView+YYAdd.h b/samples/LFLiveKitDemo/LFLiveKitDemo/category/UIView+YYAdd.h similarity index 84% rename from LFLiveKitDemo/LFLiveKitDemo/category/UIView+YYAdd.h rename to samples/LFLiveKitDemo/LFLiveKitDemo/category/UIView+YYAdd.h index 0870c11c..8b49be66 100644 --- a/LFLiveKitDemo/LFLiveKitDemo/category/UIView+YYAdd.h +++ b/samples/LFLiveKitDemo/LFLiveKitDemo/category/UIView+YYAdd.h @@ -17,13 +17,13 @@ Create a snapshot image of the complete view hierarchy. This method should be called in main thread. */ -- (UIImage *)snapshotImage; +- (nullable UIImage *)snapshotImage; /** Create a snapshot PDF of the complete view hierarchy. This method should be called in main thread. */ -- (NSData *)snapshotPDF; +- (nullable NSData *)snapshotPDF; /** Shortcut to set the view.layer's shadow @@ -32,13 +32,13 @@ @param offset Shadow offset @param radius Shadow radius */ -- (void)setLayerShadow:(UIColor*)color offset:(CGSize)offset radius:(CGFloat)radius; +- (void)setLayerShadow:(nullable UIColor*)color offset:(CGSize)offset radius:(CGFloat)radius; /** * 设置阴影 郭liyuan+ */ - (void) makeInsetShadow; - (void) makeInsetShadowWithRadius:(float)radius Alpha:(float)alpha; -- (void) makeInsetShadowWithRadius:(float)radius Color:(UIColor *)color Directions:(NSArray *)directions; +- (void) makeInsetShadowWithRadius:(float)radius Color:(nullable UIColor *)color Directions:(nullable NSArray *)directions; /** Remove all subviews. @@ -50,7 +50,7 @@ /** Returns the view's view controller (may be nil). */ -@property (nonatomic, readonly) UIViewController *viewController; +@property (nonatomic, readonly,nullable) UIViewController *viewController; @property (nonatomic) CGFloat left; ///< Shortcut for frame.origin.x. @property (nonatomic) CGFloat top; ///< Shortcut for frame.origin.y @@ -78,7 +78,7 @@ If view is nil, this method instead converts to window base coordinates. @return The point converted to the coordinate system of view. */ -- (CGPoint)convertPoint:(CGPoint)point toViewOrWindow:(UIView *)view; +- (CGPoint)convertPoint:(CGPoint)point toViewOrWindow:(nullable UIView *)view; /** Converts a point from the coordinate system of a given view or window to that of the receiver. @@ -88,7 +88,7 @@ If view is nil, this method instead converts from window base coordinates. @return The point converted to the local coordinate system (bounds) of the receiver. */ -- (CGPoint)convertPoint:(CGPoint)point fromViewOrWindow:(UIView *)view; +- (CGPoint)convertPoint:(CGPoint)point fromViewOrWindow:(nullable UIView *)view; /** Converts a rectangle from the receiver's coordinate system to that of another view or window. @@ -97,7 +97,7 @@ @param view The view or window that is the target of the conversion operation. If view is nil, this method instead converts to window base coordinates. @return The converted rectangle. */ -- (CGRect)convertRect:(CGRect)rect toViewOrWindow:(UIView *)view; +- (CGRect)convertRect:(CGRect)rect toViewOrWindow:(nullable UIView *)view; /** Converts a rectangle from the coordinate system of another view or window to that of the receiver. @@ -107,7 +107,7 @@ If view is nil, this method instead converts from window base coordinates. @return The converted rectangle. */ -- (CGRect)convertRect:(CGRect)rect fromViewOrWindow:(UIView *)view; +- (CGRect)convertRect:(CGRect)rect fromViewOrWindow:(nullable UIView *)view; /** * 返回响应者链上的任意Objc @@ -128,5 +128,5 @@ - (void)removeAllGesturesWithSubViews; /// 在 block 内禁用动画 -+ (void)disableAnimationWithBlock:(void (^)(void))block; ++ (void)disableAnimationWithBlock:(nullable void (^)(void))block; @end diff --git a/LFLiveKitDemo/LFLiveKitDemo/category/UIView+YYAdd.m b/samples/LFLiveKitDemo/LFLiveKitDemo/category/UIView+YYAdd.m similarity index 100% rename from LFLiveKitDemo/LFLiveKitDemo/category/UIView+YYAdd.m rename to samples/LFLiveKitDemo/LFLiveKitDemo/category/UIView+YYAdd.m diff --git a/LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty@2x.png b/samples/LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty@2x.png similarity index 100% rename from LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty@2x.png rename to samples/LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty@2x.png diff --git a/LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty@3x.png b/samples/LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty@3x.png similarity index 100% rename from LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty@3x.png rename to samples/LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty@3x.png diff --git a/LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty_close@2x.png b/samples/LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty_close@2x.png similarity index 100% rename from LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty_close@2x.png rename to samples/LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty_close@2x.png diff --git a/LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty_close@3x.png b/samples/LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty_close@3x.png similarity index 100% rename from LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty_close@3x.png rename to samples/LFLiveKitDemo/LFLiveKitDemo/images/camra_beauty_close@3x.png diff --git a/LFLiveKitDemo/LFLiveKitDemo/images/camra_preview@2x.png b/samples/LFLiveKitDemo/LFLiveKitDemo/images/camra_preview@2x.png similarity index 100% rename from LFLiveKitDemo/LFLiveKitDemo/images/camra_preview@2x.png rename to samples/LFLiveKitDemo/LFLiveKitDemo/images/camra_preview@2x.png diff --git a/LFLiveKitDemo/LFLiveKitDemo/images/camra_preview@3x.png b/samples/LFLiveKitDemo/LFLiveKitDemo/images/camra_preview@3x.png similarity index 100% rename from LFLiveKitDemo/LFLiveKitDemo/images/camra_preview@3x.png rename to samples/LFLiveKitDemo/LFLiveKitDemo/images/camra_preview@3x.png diff --git a/LFLiveKitDemo/LFLiveKitDemo/images/close_preview@2x.png b/samples/LFLiveKitDemo/LFLiveKitDemo/images/close_preview@2x.png similarity index 100% rename from LFLiveKitDemo/LFLiveKitDemo/images/close_preview@2x.png rename to samples/LFLiveKitDemo/LFLiveKitDemo/images/close_preview@2x.png diff --git a/LFLiveKitDemo/LFLiveKitDemo/images/close_preview@3x.png b/samples/LFLiveKitDemo/LFLiveKitDemo/images/close_preview@3x.png similarity index 100% rename from LFLiveKitDemo/LFLiveKitDemo/images/close_preview@3x.png rename to samples/LFLiveKitDemo/LFLiveKitDemo/images/close_preview@3x.png diff --git a/samples/LFLiveKitDemo/LFLiveKitDemo/images/ios-29x29.png b/samples/LFLiveKitDemo/LFLiveKitDemo/images/ios-29x29.png new file mode 100644 index 00000000..03997000 Binary files /dev/null and b/samples/LFLiveKitDemo/LFLiveKitDemo/images/ios-29x29.png differ diff --git a/LFLiveKitDemo/LFLiveKitDemo/main.m b/samples/LFLiveKitDemo/LFLiveKitDemo/main.m similarity index 90% rename from LFLiveKitDemo/LFLiveKitDemo/main.m rename to samples/LFLiveKitDemo/LFLiveKitDemo/main.m index 9eec8c1c..fb381fac 100644 --- a/LFLiveKitDemo/LFLiveKitDemo/main.m +++ b/samples/LFLiveKitDemo/LFLiveKitDemo/main.m @@ -2,7 +2,7 @@ // main.m // LFLiveKitDemo // -// Created by admin on 16/6/8. +// Created by admin on 16/8/30. // Copyright © 2016年 admin. All rights reserved. // diff --git a/samples/LFLiveKitDemo/Podfile b/samples/LFLiveKitDemo/Podfile new file mode 100644 index 00000000..340cad85 --- /dev/null +++ b/samples/LFLiveKitDemo/Podfile @@ -0,0 +1,6 @@ +source 'https://github.com/CocoaPods/Specs.git' +platform :ios,'7.0' + +target “LFLiveKitDemo” do + pod 'LFLiveKit', :path => '../../.' +end diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo.xcodeproj/project.pbxproj b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo.xcodeproj/project.pbxproj new file mode 100644 index 00000000..71e18b7a --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo.xcodeproj/project.pbxproj @@ -0,0 +1,519 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 843591661DD201D200811FC7 /* LFLiveKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8495F6CE1DB8F37E00542124 /* LFLiveKit.framework */; }; + 8495F6B01DB8F37300542124 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8495F6AF1DB8F37300542124 /* main.m */; }; + 8495F6B31DB8F37300542124 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8495F6B21DB8F37300542124 /* AppDelegate.m */; }; + 8495F6B61DB8F37300542124 /* FirstViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8495F6B51DB8F37300542124 /* FirstViewController.m */; }; + 8495F6B91DB8F37300542124 /* SecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8495F6B81DB8F37300542124 /* SecondViewController.m */; }; + 8495F6BC1DB8F37300542124 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8495F6BA1DB8F37300542124 /* Main.storyboard */; }; + 8495F6BE1DB8F37300542124 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8495F6BD1DB8F37300542124 /* Assets.xcassets */; }; + 8495F6C11DB8F37300542124 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8495F6BF1DB8F37300542124 /* LaunchScreen.storyboard */; }; + 84D003561DB8F7FA00560583 /* UIControl+YYAdd.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D003471DB8F7FA00560583 /* UIControl+YYAdd.m */; }; + 84D003571DB8F7FA00560583 /* UIView+YYAdd.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D003491DB8F7FA00560583 /* UIView+YYAdd.m */; }; + 84D003581DB8F7FA00560583 /* camra_beauty@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D0034B1DB8F7FA00560583 /* camra_beauty@2x.png */; }; + 84D003591DB8F7FA00560583 /* camra_beauty@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D0034C1DB8F7FA00560583 /* camra_beauty@3x.png */; }; + 84D0035A1DB8F7FA00560583 /* camra_beauty_close@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D0034D1DB8F7FA00560583 /* camra_beauty_close@2x.png */; }; + 84D0035B1DB8F7FA00560583 /* camra_beauty_close@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D0034E1DB8F7FA00560583 /* camra_beauty_close@3x.png */; }; + 84D0035C1DB8F7FA00560583 /* camra_preview@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D0034F1DB8F7FA00560583 /* camra_preview@2x.png */; }; + 84D0035D1DB8F7FA00560583 /* camra_preview@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D003501DB8F7FA00560583 /* camra_preview@3x.png */; }; + 84D0035E1DB8F7FA00560583 /* close_preview@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D003511DB8F7FA00560583 /* close_preview@2x.png */; }; + 84D0035F1DB8F7FA00560583 /* close_preview@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D003521DB8F7FA00560583 /* close_preview@3x.png */; }; + 84D003601DB8F7FA00560583 /* ios-29x29.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D003531DB8F7FA00560583 /* ios-29x29.png */; }; + 84D003611DB8F7FA00560583 /* LFLivePreview.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D003551DB8F7FA00560583 /* LFLivePreview.m */; }; + 84D003641DB8F83400560583 /* libstdc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D003631DB8F83400560583 /* libstdc++.tbd */; }; + 84D0036A1DB8F85E00560583 /* VideoToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D003691DB8F85E00560583 /* VideoToolbox.framework */; }; + 84D0036C1DB8F86700560583 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D0036B1DB8F86700560583 /* AudioToolbox.framework */; }; + 84D0036E1DB8F86D00560583 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D0036D1DB8F86D00560583 /* AVFoundation.framework */; }; + 84D003711DB8F8BD00560583 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D003701DB8F8BD00560583 /* UIKit.framework */; }; + 84D003731DB8F8C200560583 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D003721DB8F8C200560583 /* Foundation.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 843591641DD201CC00811FC7 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 8495F6C81DB8F37E00542124 /* LFLiveKit.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = 8495F66A1DB8F14600542124; + remoteInfo = LFLiveKitFramework; + }; + 8495F6CD1DB8F37E00542124 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 8495F6C81DB8F37E00542124 /* LFLiveKit.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 84D8B3901D7574D600752B56; + remoteInfo = LFLiveKit; + }; + 8495F6CF1DB8F37E00542124 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 8495F6C81DB8F37E00542124 /* LFLiveKit.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 8495F66B1DB8F14600542124; + remoteInfo = LFLiveKitFramework; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 843591671DD204FA00811FC7 /* libstdc++.6.0.9.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libstdc++.6.0.9.tbd"; path = "usr/lib/libstdc++.6.0.9.tbd"; sourceTree = SDKROOT; }; + 8495F6AB1DB8F37300542124 /* LFLiveKitFrameworkDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LFLiveKitFrameworkDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 8495F6AF1DB8F37300542124 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 8495F6B11DB8F37300542124 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 8495F6B21DB8F37300542124 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 8495F6B41DB8F37300542124 /* FirstViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FirstViewController.h; sourceTree = ""; }; + 8495F6B51DB8F37300542124 /* FirstViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FirstViewController.m; sourceTree = ""; }; + 8495F6B71DB8F37300542124 /* SecondViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SecondViewController.h; sourceTree = ""; }; + 8495F6B81DB8F37300542124 /* SecondViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SecondViewController.m; sourceTree = ""; }; + 8495F6BB1DB8F37300542124 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 8495F6BD1DB8F37300542124 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 8495F6C01DB8F37300542124 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 8495F6C21DB8F37300542124 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 8495F6C81DB8F37E00542124 /* LFLiveKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = LFLiveKit.xcodeproj; path = ../../FrameWork/LFLiveKit.xcodeproj; sourceTree = ""; }; + 8495F6D51DB8F49800542124 /* GPUImage.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GPUImage.framework; path = vendors/GPUImage.framework; sourceTree = ""; }; + 8495F6D61DB8F49800542124 /* pili-librtmp.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = "pili-librtmp.framework"; path = "vendors/pili-librtmp.framework"; sourceTree = ""; }; + 84D003461DB8F7FA00560583 /* UIControl+YYAdd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIControl+YYAdd.h"; sourceTree = ""; }; + 84D003471DB8F7FA00560583 /* UIControl+YYAdd.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIControl+YYAdd.m"; sourceTree = ""; }; + 84D003481DB8F7FA00560583 /* UIView+YYAdd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+YYAdd.h"; sourceTree = ""; }; + 84D003491DB8F7FA00560583 /* UIView+YYAdd.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+YYAdd.m"; sourceTree = ""; }; + 84D0034B1DB8F7FA00560583 /* camra_beauty@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty@2x.png"; sourceTree = ""; }; + 84D0034C1DB8F7FA00560583 /* camra_beauty@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty@3x.png"; sourceTree = ""; }; + 84D0034D1DB8F7FA00560583 /* camra_beauty_close@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty_close@2x.png"; sourceTree = ""; }; + 84D0034E1DB8F7FA00560583 /* camra_beauty_close@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty_close@3x.png"; sourceTree = ""; }; + 84D0034F1DB8F7FA00560583 /* camra_preview@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_preview@2x.png"; sourceTree = ""; }; + 84D003501DB8F7FA00560583 /* camra_preview@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_preview@3x.png"; sourceTree = ""; }; + 84D003511DB8F7FA00560583 /* close_preview@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@2x.png"; sourceTree = ""; }; + 84D003521DB8F7FA00560583 /* close_preview@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@3x.png"; sourceTree = ""; }; + 84D003531DB8F7FA00560583 /* ios-29x29.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ios-29x29.png"; sourceTree = ""; }; + 84D003541DB8F7FA00560583 /* LFLivePreview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFLivePreview.h; sourceTree = ""; }; + 84D003551DB8F7FA00560583 /* LFLivePreview.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFLivePreview.m; sourceTree = ""; }; + 84D003631DB8F83400560583 /* libstdc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libstdc++.tbd"; path = "usr/lib/libstdc++.tbd"; sourceTree = SDKROOT; }; + 84D003651DB8F84000560583 /* libresolv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.tbd; path = usr/lib/libresolv.tbd; sourceTree = SDKROOT; }; + 84D003671DB8F84800560583 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; + 84D003691DB8F85E00560583 /* VideoToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = VideoToolbox.framework; path = System/Library/Frameworks/VideoToolbox.framework; sourceTree = SDKROOT; }; + 84D0036B1DB8F86700560583 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; + 84D0036D1DB8F86D00560583 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; + 84D003701DB8F8BD00560583 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + 84D003721DB8F8C200560583 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 8495F6A81DB8F37300542124 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 843591661DD201D200811FC7 /* LFLiveKit.framework in Frameworks */, + 84D003731DB8F8C200560583 /* Foundation.framework in Frameworks */, + 84D003711DB8F8BD00560583 /* UIKit.framework in Frameworks */, + 84D0036E1DB8F86D00560583 /* AVFoundation.framework in Frameworks */, + 84D0036C1DB8F86700560583 /* AudioToolbox.framework in Frameworks */, + 84D0036A1DB8F85E00560583 /* VideoToolbox.framework in Frameworks */, + 84D003641DB8F83400560583 /* libstdc++.tbd in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 8495F6A21DB8F37300542124 = { + isa = PBXGroup; + children = ( + 8495F6C81DB8F37E00542124 /* LFLiveKit.xcodeproj */, + 8495F6AD1DB8F37300542124 /* LFLiveKitFrameworkDemo */, + 8495F6AC1DB8F37300542124 /* Products */, + 8495F6D41DB8F49800542124 /* Frameworks */, + ); + sourceTree = ""; + }; + 8495F6AC1DB8F37300542124 /* Products */ = { + isa = PBXGroup; + children = ( + 8495F6AB1DB8F37300542124 /* LFLiveKitFrameworkDemo.app */, + ); + name = Products; + sourceTree = ""; + }; + 8495F6AD1DB8F37300542124 /* LFLiveKitFrameworkDemo */ = { + isa = PBXGroup; + children = ( + 8495F6B11DB8F37300542124 /* AppDelegate.h */, + 8495F6B21DB8F37300542124 /* AppDelegate.m */, + 8495F6B41DB8F37300542124 /* FirstViewController.h */, + 8495F6B51DB8F37300542124 /* FirstViewController.m */, + 8495F6B71DB8F37300542124 /* SecondViewController.h */, + 8495F6B81DB8F37300542124 /* SecondViewController.m */, + 84D003451DB8F7FA00560583 /* category */, + 84D0034A1DB8F7FA00560583 /* images */, + 84D003541DB8F7FA00560583 /* LFLivePreview.h */, + 84D003551DB8F7FA00560583 /* LFLivePreview.m */, + 8495F6BA1DB8F37300542124 /* Main.storyboard */, + 8495F6BD1DB8F37300542124 /* Assets.xcassets */, + 8495F6BF1DB8F37300542124 /* LaunchScreen.storyboard */, + 8495F6C21DB8F37300542124 /* Info.plist */, + 8495F6AE1DB8F37300542124 /* Supporting Files */, + ); + path = LFLiveKitFrameworkDemo; + sourceTree = ""; + }; + 8495F6AE1DB8F37300542124 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 8495F6AF1DB8F37300542124 /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 8495F6C91DB8F37E00542124 /* Products */ = { + isa = PBXGroup; + children = ( + 8495F6CE1DB8F37E00542124 /* LFLiveKit.framework */, + 8495F6D01DB8F37E00542124 /* LFLiveKit.framework */, + ); + name = Products; + sourceTree = ""; + }; + 8495F6D41DB8F49800542124 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 843591671DD204FA00811FC7 /* libstdc++.6.0.9.tbd */, + 84D003721DB8F8C200560583 /* Foundation.framework */, + 84D003701DB8F8BD00560583 /* UIKit.framework */, + 84D0036D1DB8F86D00560583 /* AVFoundation.framework */, + 84D0036B1DB8F86700560583 /* AudioToolbox.framework */, + 84D003691DB8F85E00560583 /* VideoToolbox.framework */, + 84D003671DB8F84800560583 /* libz.tbd */, + 84D003651DB8F84000560583 /* libresolv.tbd */, + 84D003631DB8F83400560583 /* libstdc++.tbd */, + 8495F6D51DB8F49800542124 /* GPUImage.framework */, + 8495F6D61DB8F49800542124 /* pili-librtmp.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 84D003451DB8F7FA00560583 /* category */ = { + isa = PBXGroup; + children = ( + 84D003461DB8F7FA00560583 /* UIControl+YYAdd.h */, + 84D003471DB8F7FA00560583 /* UIControl+YYAdd.m */, + 84D003481DB8F7FA00560583 /* UIView+YYAdd.h */, + 84D003491DB8F7FA00560583 /* UIView+YYAdd.m */, + ); + path = category; + sourceTree = ""; + }; + 84D0034A1DB8F7FA00560583 /* images */ = { + isa = PBXGroup; + children = ( + 84D0034B1DB8F7FA00560583 /* camra_beauty@2x.png */, + 84D0034C1DB8F7FA00560583 /* camra_beauty@3x.png */, + 84D0034D1DB8F7FA00560583 /* camra_beauty_close@2x.png */, + 84D0034E1DB8F7FA00560583 /* camra_beauty_close@3x.png */, + 84D0034F1DB8F7FA00560583 /* camra_preview@2x.png */, + 84D003501DB8F7FA00560583 /* camra_preview@3x.png */, + 84D003511DB8F7FA00560583 /* close_preview@2x.png */, + 84D003521DB8F7FA00560583 /* close_preview@3x.png */, + 84D003531DB8F7FA00560583 /* ios-29x29.png */, + ); + path = images; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 8495F6AA1DB8F37300542124 /* LFLiveKitFrameworkDemo */ = { + isa = PBXNativeTarget; + buildConfigurationList = 8495F6C51DB8F37300542124 /* Build configuration list for PBXNativeTarget "LFLiveKitFrameworkDemo" */; + buildPhases = ( + 8495F6A71DB8F37300542124 /* Sources */, + 8495F6A81DB8F37300542124 /* Frameworks */, + 8495F6A91DB8F37300542124 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 843591651DD201CC00811FC7 /* PBXTargetDependency */, + ); + name = LFLiveKitFrameworkDemo; + productName = LFLiveKitFrameworkDemo; + productReference = 8495F6AB1DB8F37300542124 /* LFLiveKitFrameworkDemo.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 8495F6A31DB8F37300542124 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0800; + ORGANIZATIONNAME = admin; + TargetAttributes = { + 8495F6AA1DB8F37300542124 = { + CreatedOnToolsVersion = 8.0; + DevelopmentTeam = G497YX6CBT; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = 8495F6A61DB8F37300542124 /* Build configuration list for PBXProject "LFLiveKitFrameworkDemo" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 8495F6A21DB8F37300542124; + productRefGroup = 8495F6AC1DB8F37300542124 /* Products */; + projectDirPath = ""; + projectReferences = ( + { + ProductGroup = 8495F6C91DB8F37E00542124 /* Products */; + ProjectRef = 8495F6C81DB8F37E00542124 /* LFLiveKit.xcodeproj */; + }, + ); + projectRoot = ""; + targets = ( + 8495F6AA1DB8F37300542124 /* LFLiveKitFrameworkDemo */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXReferenceProxy section */ + 8495F6CE1DB8F37E00542124 /* LFLiveKit.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = LFLiveKit.framework; + remoteRef = 8495F6CD1DB8F37E00542124 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 8495F6D01DB8F37E00542124 /* LFLiveKit.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = LFLiveKit.framework; + remoteRef = 8495F6CF1DB8F37E00542124 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; +/* End PBXReferenceProxy section */ + +/* Begin PBXResourcesBuildPhase section */ + 8495F6A91DB8F37300542124 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 84D0035A1DB8F7FA00560583 /* camra_beauty_close@2x.png in Resources */, + 8495F6C11DB8F37300542124 /* LaunchScreen.storyboard in Resources */, + 84D003581DB8F7FA00560583 /* camra_beauty@2x.png in Resources */, + 8495F6BE1DB8F37300542124 /* Assets.xcassets in Resources */, + 84D0035D1DB8F7FA00560583 /* camra_preview@3x.png in Resources */, + 84D0035B1DB8F7FA00560583 /* camra_beauty_close@3x.png in Resources */, + 84D003601DB8F7FA00560583 /* ios-29x29.png in Resources */, + 84D0035F1DB8F7FA00560583 /* close_preview@3x.png in Resources */, + 84D0035E1DB8F7FA00560583 /* close_preview@2x.png in Resources */, + 8495F6BC1DB8F37300542124 /* Main.storyboard in Resources */, + 84D0035C1DB8F7FA00560583 /* camra_preview@2x.png in Resources */, + 84D003591DB8F7FA00560583 /* camra_beauty@3x.png in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 8495F6A71DB8F37300542124 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 84D003561DB8F7FA00560583 /* UIControl+YYAdd.m in Sources */, + 8495F6B91DB8F37300542124 /* SecondViewController.m in Sources */, + 84D003571DB8F7FA00560583 /* UIView+YYAdd.m in Sources */, + 8495F6B31DB8F37300542124 /* AppDelegate.m in Sources */, + 84D003611DB8F7FA00560583 /* LFLivePreview.m in Sources */, + 8495F6B61DB8F37300542124 /* FirstViewController.m in Sources */, + 8495F6B01DB8F37300542124 /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 843591651DD201CC00811FC7 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = LFLiveKitFramework; + targetProxy = 843591641DD201CC00811FC7 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 8495F6BA1DB8F37300542124 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 8495F6BB1DB8F37300542124 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 8495F6BF1DB8F37300542124 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 8495F6C01DB8F37300542124 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 8495F6C31DB8F37300542124 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 8495F6C41DB8F37300542124 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 8495F6C61DB8F37300542124 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = G497YX6CBT; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + HEADER_SEARCH_PATHS = ""; + INFOPLIST_FILE = LFLiveKitFrameworkDemo/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + OTHER_LDFLAGS = ( + "$(inherited)", + "-ObjC", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKitFrameworkDemo; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 8495F6C71DB8F37300542124 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = G497YX6CBT; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + HEADER_SEARCH_PATHS = ""; + INFOPLIST_FILE = LFLiveKitFrameworkDemo/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + OTHER_LDFLAGS = ( + "$(inherited)", + "-ObjC", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKitFrameworkDemo; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 8495F6A61DB8F37300542124 /* Build configuration list for PBXProject "LFLiveKitFrameworkDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 8495F6C31DB8F37300542124 /* Debug */, + 8495F6C41DB8F37300542124 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 8495F6C51DB8F37300542124 /* Build configuration list for PBXNativeTarget "LFLiveKitFrameworkDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 8495F6C61DB8F37300542124 /* Debug */, + 8495F6C71DB8F37300542124 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 8495F6A31DB8F37300542124 /* Project object */; +} diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/AppDelegate.h b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/AppDelegate.h new file mode 100644 index 00000000..caa92516 --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/AppDelegate.h @@ -0,0 +1,17 @@ +// +// AppDelegate.h +// LFLiveKitFrameworkDemo +// +// Created by admin on 2016/10/20. +// Copyright © 2016年 admin. All rights reserved. +// + +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + + +@end + diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/AppDelegate.m b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/AppDelegate.m new file mode 100644 index 00000000..eb453b9c --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/AppDelegate.m @@ -0,0 +1,51 @@ +// +// AppDelegate.m +// LFLiveKitFrameworkDemo +// +// Created by admin on 2016/10/20. +// Copyright © 2016年 admin. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + return YES; +} + + +- (void)applicationWillResignActive:(UIApplication *)application { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. +} + + +- (void)applicationDidEnterBackground:(UIApplication *)application { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + + +- (void)applicationWillEnterForeground:(UIApplication *)application { + // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. +} + + +- (void)applicationDidBecomeActive:(UIApplication *)application { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + + +- (void)applicationWillTerminate:(UIApplication *)application { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + + +@end diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Assets.xcassets/AppIcon.appiconset/Contents.json b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..118c98f7 --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,38 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Assets.xcassets/first.imageset/Contents.json b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Assets.xcassets/first.imageset/Contents.json new file mode 100644 index 00000000..33a74510 --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Assets.xcassets/first.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "first.pdf" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Assets.xcassets/first.imageset/first.pdf b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Assets.xcassets/first.imageset/first.pdf new file mode 100644 index 00000000..47d911de Binary files /dev/null and b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Assets.xcassets/first.imageset/first.pdf differ diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Assets.xcassets/second.imageset/Contents.json b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Assets.xcassets/second.imageset/Contents.json new file mode 100644 index 00000000..03bd9c92 --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Assets.xcassets/second.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "second.pdf" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Assets.xcassets/second.imageset/second.pdf b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Assets.xcassets/second.imageset/second.pdf new file mode 100644 index 00000000..401614e2 Binary files /dev/null and b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Assets.xcassets/second.imageset/second.pdf differ diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Base.lproj/LaunchScreen.storyboard b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 00000000..fdf3f97d --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Base.lproj/Main.storyboard b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Base.lproj/Main.storyboard new file mode 100644 index 00000000..3f958ee8 --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Base.lproj/Main.storyboard @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/FirstViewController.h b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/FirstViewController.h new file mode 100644 index 00000000..4ebdd850 --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/FirstViewController.h @@ -0,0 +1,15 @@ +// +// FirstViewController.h +// LFLiveKitFrameworkDemo +// +// Created by admin on 2016/10/20. +// Copyright © 2016年 admin. All rights reserved. +// + +#import + +@interface FirstViewController : UIViewController + + +@end + diff --git a/LFLiveKitDemo/LFLiveKitDemo/ViewController.m b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/FirstViewController.m similarity index 55% rename from LFLiveKitDemo/LFLiveKitDemo/ViewController.m rename to samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/FirstViewController.m index 609ca50b..c0eb0ea2 100644 --- a/LFLiveKitDemo/LFLiveKitDemo/ViewController.m +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/FirstViewController.m @@ -1,29 +1,30 @@ // -// ViewController.m -// LFLiveKitDemo +// FirstViewController.m +// LFLiveKitFrameworkDemo // -// Created by admin on 16/6/8. +// Created by admin on 2016/10/20. // Copyright © 2016年 admin. All rights reserved. // -#import "ViewController.h" -#import "LFLivePreview.h" +#import "FirstViewController.h" +#import -@interface ViewController () +@interface FirstViewController () @end -@implementation ViewController +@implementation FirstViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. - [self.view addSubview:[[LFLivePreview alloc] initWithFrame:self.view.bounds]]; } + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } + @end diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Info.plist b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Info.plist new file mode 100644 index 00000000..a0c3d666 --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/Info.plist @@ -0,0 +1,52 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + NSCameraUsageDescription + .. + NSMicrophoneUsageDescription + .. + UIRequiredDeviceCapabilities + + armv7 + + UIStatusBarTintParameters + + UINavigationBar + + Style + UIBarStyleDefault + Translucent + + + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/LFLivePreview.h b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/LFLivePreview.h new file mode 100755 index 00000000..14a93625 --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/LFLivePreview.h @@ -0,0 +1,13 @@ +// +// LFLivePreview.h +// LFLiveKit +// +// Created by 倾慕 on 16/5/2. +// Copyright © 2016年 live Interactive. All rights reserved. +// + +#import + +@interface LFLivePreview : UIView + +@end diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/LFLivePreview.m b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/LFLivePreview.m new file mode 100755 index 00000000..9bce00da --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/LFLivePreview.m @@ -0,0 +1,374 @@ +// +// LFLivePreview.m +// LFLiveKit +// +// Created by 倾慕 on 16/5/2. +// Copyright © 2016年 live Interactive. All rights reserved. +// + +#import "LFLivePreview.h" +#import "UIControl+YYAdd.h" +#import "UIView+YYAdd.h" +#import + +inline static NSString *formatedSpeed(float bytes, float elapsed_milli) { + if (elapsed_milli <= 0) { + return @"N/A"; + } + + if (bytes <= 0) { + return @"0 KB/s"; + } + + float bytes_per_sec = ((float)bytes) * 1000.f / elapsed_milli; + if (bytes_per_sec >= 1000 * 1000) { + return [NSString stringWithFormat:@"%.2f MB/s", ((float)bytes_per_sec) / 1000 / 1000]; + } else if (bytes_per_sec >= 1000) { + return [NSString stringWithFormat:@"%.1f KB/s", ((float)bytes_per_sec) / 1000]; + } else { + return [NSString stringWithFormat:@"%ld B/s", (long)bytes_per_sec]; + } +} + +@interface LFLivePreview () + +@property (nonatomic, strong) UIButton *beautyButton; +@property (nonatomic, strong) UIButton *cameraButton; +@property (nonatomic, strong) UIButton *closeButton; +@property (nonatomic, strong) UIButton *startLiveButton; +@property (nonatomic, strong) UIView *containerView; +@property (nonatomic, strong) LFLiveDebug *debugInfo; +@property (nonatomic, strong) LFLiveSession *session; +@property (nonatomic, strong) UILabel *stateLabel; + +@end + +@implementation LFLivePreview + +- (instancetype)initWithFrame:(CGRect)frame { + if (self = [super initWithFrame:frame]) { + self.backgroundColor = [UIColor clearColor]; + [self requestAccessForVideo]; + [self requestAccessForAudio]; + [self addSubview:self.containerView]; + [self.containerView addSubview:self.stateLabel]; + [self.containerView addSubview:self.closeButton]; + [self.containerView addSubview:self.cameraButton]; + [self.containerView addSubview:self.beautyButton]; + [self.containerView addSubview:self.startLiveButton]; + } + return self; +} + +#pragma mark -- Public Method +- (void)requestAccessForVideo { + __weak typeof(self) _self = self; + AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; + switch (status) { + case AVAuthorizationStatusNotDetermined: { + // 许可对话没有出现,发起授权许可 + [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { + if (granted) { + dispatch_async(dispatch_get_main_queue(), ^{ + [_self.session setRunning:YES]; + }); + } + }]; + break; + } + case AVAuthorizationStatusAuthorized: { + // 已经开启授权,可继续 + dispatch_async(dispatch_get_main_queue(), ^{ + [_self.session setRunning:YES]; + }); + break; + } + case AVAuthorizationStatusDenied: + case AVAuthorizationStatusRestricted: + // 用户明确地拒绝授权,或者相机设备无法访问 + + break; + default: + break; + } +} + +- (void)requestAccessForAudio { + AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]; + switch (status) { + case AVAuthorizationStatusNotDetermined: { + [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) { + }]; + break; + } + case AVAuthorizationStatusAuthorized: { + break; + } + case AVAuthorizationStatusDenied: + case AVAuthorizationStatusRestricted: + break; + default: + break; + } +} + +#pragma mark -- LFStreamingSessionDelegate +/** live status changed will callback */ +- (void)liveSession:(nullable LFLiveSession *)session liveStateDidChange:(LFLiveState)state { + NSLog(@"liveStateDidChange: %ld", state); + switch (state) { + case LFLiveReady: + _stateLabel.text = @"未连接"; + break; + case LFLivePending: + _stateLabel.text = @"连接中"; + break; + case LFLiveStart: + _stateLabel.text = @"已连接"; + break; + case LFLiveError: + _stateLabel.text = @"连接错误"; + break; + case LFLiveStop: + _stateLabel.text = @"未连接"; + break; + default: + break; + } +} + +/** live debug info callback */ +- (void)liveSession:(nullable LFLiveSession *)session debugInfo:(nullable LFLiveDebug *)debugInfo { + NSLog(@"debugInfo uploadSpeed: %@", formatedSpeed(debugInfo.currentBandwidth, debugInfo.elapsedMilli)); +} + +/** callback socket errorcode */ +- (void)liveSession:(nullable LFLiveSession *)session errorCode:(LFLiveSocketErrorCode)errorCode { + NSLog(@"errorCode: %ld", errorCode); +} + +#pragma mark -- Getter Setter +- (LFLiveSession *)session { + if (!_session) { + /** 发现大家有不会用横屏的请注意啦,横屏需要在ViewController supportedInterfaceOrientations修改方向 默认竖屏 ****/ + /** 发现大家有不会用横屏的请注意啦,横屏需要在ViewController supportedInterfaceOrientations修改方向 默认竖屏 ****/ + /** 发现大家有不会用横屏的请注意啦,横屏需要在ViewController supportedInterfaceOrientations修改方向 默认竖屏 ****/ + + + /***  默认分辨率368 * 640 音频:44.1 iphone6以上48 双声道 方向竖屏 ***/ + LFLiveVideoConfiguration *videoConfiguration = [LFLiveVideoConfiguration new]; + videoConfiguration.videoSize = CGSizeMake(360, 640); + videoConfiguration.videoBitRate = 800*1024; + videoConfiguration.videoMaxBitRate = 1000*1024; + videoConfiguration.videoMinBitRate = 500*1024; + videoConfiguration.videoFrameRate = 24; + videoConfiguration.videoMaxKeyframeInterval = 48; + videoConfiguration.outputImageOrientation = UIInterfaceOrientationPortrait; + videoConfiguration.autorotate = NO; + videoConfiguration.sessionPreset = LFCaptureSessionPreset720x1280; + _session = [[LFLiveSession alloc] initWithAudioConfiguration:[LFLiveAudioConfiguration defaultConfiguration] videoConfiguration:videoConfiguration captureType:LFLiveCaptureDefaultMask]; + + /**   自己定制单声道 */ + /* + LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; + audioConfiguration.numberOfChannels = 1; + audioConfiguration.audioBitrate = LFLiveAudioBitRate_64Kbps; + audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; + _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:[LFLiveVideoConfiguration defaultConfiguration]]; + */ + + /**   自己定制高质量音频96K */ + /* + LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; + audioConfiguration.numberOfChannels = 2; + audioConfiguration.audioBitrate = LFLiveAudioBitRate_96Kbps; + audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; + _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:[LFLiveVideoConfiguration defaultConfiguration]]; + */ + + /**   自己定制高质量音频96K 分辨率设置为540*960 方向竖屏 */ + + /* + LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; + audioConfiguration.numberOfChannels = 2; + audioConfiguration.audioBitrate = LFLiveAudioBitRate_96Kbps; + audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; + + LFLiveVideoConfiguration *videoConfiguration = [LFLiveVideoConfiguration new]; + videoConfiguration.videoSize = CGSizeMake(540, 960); + videoConfiguration.videoBitRate = 800*1024; + videoConfiguration.videoMaxBitRate = 1000*1024; + videoConfiguration.videoMinBitRate = 500*1024; + videoConfiguration.videoFrameRate = 24; + videoConfiguration.videoMaxKeyframeInterval = 48; + videoConfiguration.orientation = UIInterfaceOrientationPortrait; + videoConfiguration.sessionPreset = LFCaptureSessionPreset540x960; + + _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:videoConfiguration]; + */ + + + /**   自己定制高质量音频128K 分辨率设置为720*1280 方向竖屏 */ + + /* + LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; + audioConfiguration.numberOfChannels = 2; + audioConfiguration.audioBitrate = LFLiveAudioBitRate_128Kbps; + audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; + + LFLiveVideoConfiguration *videoConfiguration = [LFLiveVideoConfiguration new]; + videoConfiguration.videoSize = CGSizeMake(720, 1280); + videoConfiguration.videoBitRate = 800*1024; + videoConfiguration.videoMaxBitRate = 1000*1024; + videoConfiguration.videoMinBitRate = 500*1024; + videoConfiguration.videoFrameRate = 15; + videoConfiguration.videoMaxKeyframeInterval = 30; + videoConfiguration.landscape = NO; + videoConfiguration.sessionPreset = LFCaptureSessionPreset360x640; + + _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:videoConfiguration]; + */ + + + /**   自己定制高质量音频128K 分辨率设置为720*1280 方向横屏 */ + + /* + LFLiveAudioConfiguration *audioConfiguration = [LFLiveAudioConfiguration new]; + audioConfiguration.numberOfChannels = 2; + audioConfiguration.audioBitrate = LFLiveAudioBitRate_128Kbps; + audioConfiguration.audioSampleRate = LFLiveAudioSampleRate_44100Hz; + + LFLiveVideoConfiguration *videoConfiguration = [LFLiveVideoConfiguration new]; + videoConfiguration.videoSize = CGSizeMake(1280, 720); + videoConfiguration.videoBitRate = 800*1024; + videoConfiguration.videoMaxBitRate = 1000*1024; + videoConfiguration.videoMinBitRate = 500*1024; + videoConfiguration.videoFrameRate = 15; + videoConfiguration.videoMaxKeyframeInterval = 30; + videoConfiguration.landscape = YES; + videoConfiguration.sessionPreset = LFCaptureSessionPreset720x1280; + + _session = [[LFLiveSession alloc] initWithAudioConfiguration:audioConfiguration videoConfiguration:videoConfiguration]; + */ + + _session.delegate = self; + _session.showDebugInfo = NO; + _session.preView = self; + + /*本地存储*/ +// _session.saveLocalVideo = YES; +// NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.mp4"]; +// unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie +// NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie]; +// _session.saveLocalVideoPath = movieURL; + + + UIImageView *imageView = [[UIImageView alloc] init]; + imageView.alpha = 0.8; + imageView.frame = CGRectMake(100, 100, 29, 29); + imageView.image = [UIImage imageNamed:@"ios-29x29"]; + _session.warterMarkView = imageView; + + } + return _session; +} + +- (UIView *)containerView { + if (!_containerView) { + _containerView = [UIView new]; + _containerView.frame = self.bounds; + _containerView.backgroundColor = [UIColor clearColor]; + _containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + } + return _containerView; +} + +- (UILabel *)stateLabel { + if (!_stateLabel) { + _stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 80, 40)]; + _stateLabel.text = @"未连接"; + _stateLabel.textColor = [UIColor whiteColor]; + _stateLabel.font = [UIFont boldSystemFontOfSize:14.f]; + } + return _stateLabel; +} + +- (UIButton *)closeButton { + if (!_closeButton) { + _closeButton = [UIButton new]; + _closeButton.size = CGSizeMake(44, 44); + _closeButton.left = self.width - 10 - _closeButton.width; + _closeButton.top = 20; + [_closeButton setImage:[UIImage imageNamed:@"close_preview"] forState:UIControlStateNormal]; + _closeButton.exclusiveTouch = YES; + [_closeButton addBlockForControlEvents:UIControlEventTouchUpInside block:^(id sender) { + + }]; + } + return _closeButton; +} + +- (UIButton *)cameraButton { + if (!_cameraButton) { + _cameraButton = [UIButton new]; + _cameraButton.size = CGSizeMake(44, 44); + _cameraButton.origin = CGPointMake(_closeButton.left - 10 - _cameraButton.width, 20); + [_cameraButton setImage:[UIImage imageNamed:@"camra_preview"] forState:UIControlStateNormal]; + _cameraButton.exclusiveTouch = YES; + __weak typeof(self) _self = self; + [_cameraButton addBlockForControlEvents:UIControlEventTouchUpInside block:^(id sender) { + AVCaptureDevicePosition devicePositon = _self.session.captureDevicePosition; + _self.session.captureDevicePosition = (devicePositon == AVCaptureDevicePositionBack) ? AVCaptureDevicePositionFront : AVCaptureDevicePositionBack; + }]; + } + return _cameraButton; +} + +- (UIButton *)beautyButton { + if (!_beautyButton) { + _beautyButton = [UIButton new]; + _beautyButton.size = CGSizeMake(44, 44); + _beautyButton.origin = CGPointMake(_cameraButton.left - 10 - _beautyButton.width, 20); + [_beautyButton setImage:[UIImage imageNamed:@"camra_beauty"] forState:UIControlStateNormal]; + [_beautyButton setImage:[UIImage imageNamed:@"camra_beauty_close"] forState:UIControlStateSelected]; + _beautyButton.exclusiveTouch = YES; + __weak typeof(self) _self = self; + [_beautyButton addBlockForControlEvents:UIControlEventTouchUpInside block:^(id sender) { + _self.session.beautyFace = !_self.session.beautyFace; + _self.beautyButton.selected = !_self.session.beautyFace; + }]; + } + return _beautyButton; +} + +- (UIButton *)startLiveButton { + if (!_startLiveButton) { + _startLiveButton = [UIButton new]; + _startLiveButton.size = CGSizeMake(self.width - 60, 44); + _startLiveButton.left = 30; + _startLiveButton.bottom = self.height - 50; + _startLiveButton.layer.cornerRadius = _startLiveButton.height/2; + [_startLiveButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; + [_startLiveButton.titleLabel setFont:[UIFont systemFontOfSize:16]]; + [_startLiveButton setTitle:@"开始直播" forState:UIControlStateNormal]; + [_startLiveButton setBackgroundColor:[UIColor colorWithRed:50 green:32 blue:245 alpha:1]]; + _startLiveButton.exclusiveTouch = YES; + __weak typeof(self) _self = self; + [_startLiveButton addBlockForControlEvents:UIControlEventTouchUpInside block:^(id sender) { + _self.startLiveButton.selected = !_self.startLiveButton.selected; + if (_self.startLiveButton.selected) { + [_self.startLiveButton setTitle:@"结束直播" forState:UIControlStateNormal]; + LFLiveStreamInfo *stream = [LFLiveStreamInfo new]; + stream.url = @"rtmp://live.hkstv.hk.lxdns.com:1935/live/stream153"; + [_self.session startLive:stream]; + } else { + [_self.startLiveButton setTitle:@"开始直播" forState:UIControlStateNormal]; + [_self.session stopLive]; + } + }]; + } + return _startLiveButton; +} + +@end + diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/SecondViewController.h b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/SecondViewController.h new file mode 100644 index 00000000..2c36368c --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/SecondViewController.h @@ -0,0 +1,15 @@ +// +// SecondViewController.h +// LFLiveKitFrameworkDemo +// +// Created by admin on 2016/10/20. +// Copyright © 2016年 admin. All rights reserved. +// + +#import + +@interface SecondViewController : UIViewController + + +@end + diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/SecondViewController.m b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/SecondViewController.m new file mode 100644 index 00000000..70e009bc --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/SecondViewController.m @@ -0,0 +1,34 @@ +// +// SecondViewController.m +// LFLiveKitFrameworkDemo +// +// Created by admin on 2016/10/20. +// Copyright © 2016年 admin. All rights reserved. +// + +#import "SecondViewController.h" +#import "LFLivePreview.h" + +@interface SecondViewController () + +@end + +@implementation SecondViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view, typically from a nib. + [self.view addSubview:[[LFLivePreview alloc] initWithFrame:self.view.bounds]]; +} + + +- (UIInterfaceOrientationMask)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskPortrait; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { + return YES; +} + + +@end diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/category/UIControl+YYAdd.h b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/category/UIControl+YYAdd.h new file mode 100644 index 00000000..76f9547d --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/category/UIControl+YYAdd.h @@ -0,0 +1,71 @@ +// +// UIControl+YYAdd.h +// +// +// Created by guoyaoyuan on 13-4-5. +// Copyright (c) 2013 live Interactive. All rights reserved. +// + +#import + +/** + Provides extensions for `UIControl`. + */ +@interface UIControl (YYAdd) + +/** + Removes all targets and actions for a particular event (or events) + from an internal dispatch table. + */ +- (void)removeAllTargets; + +/** + Adds or replaces a target and action for a particular event (or events) + to an internal dispatch table. + + @param target The target object—that is, the object to which the + action message is sent. If this is nil, the responder + chain is searched for an object willing to respond to the + action message. + + @param action A selector identifying an action message. It cannot be NULL. + + @param controlEvents A bitmask specifying the control events for which the + action message is sent. + */ +- (void)setTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents; + +/** + Adds a block for a particular event (or events) to an internal dispatch table. + It will cause a strong reference to @a block. + + @param block The block which is invoked then the action message is + sent (cannot be nil). The block is retained. + + @param controlEvents A bitmask specifying the control events for which the + action message is sent. + */ +- (void)addBlockForControlEvents:(UIControlEvents)controlEvents block:(void (^)(id sender))block; + +/** + Adds or replaces a block for a particular event (or events) to an internal + dispatch table. It will cause a strong reference to @a block. + + @param block The block which is invoked then the action message is + sent (cannot be nil). The block is retained. + + @param controlEvents A bitmask specifying the control events for which the + action message is sent. + */ +- (void)setBlockForControlEvents:(UIControlEvents)controlEvents block:(void (^)(id sender))block; + +/** + Removes all blocks for a particular event (or events) from an internal + dispatch table. + + @param controlEvents A bitmask specifying the control events for which the + action message is sent. + */ +- (void)removeAllBlocksForControlEvents:(UIControlEvents)controlEvents; + +@end diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/category/UIControl+YYAdd.m b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/category/UIControl+YYAdd.m new file mode 100644 index 00000000..f9807998 --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/category/UIControl+YYAdd.m @@ -0,0 +1,105 @@ +// +// UIControl+YYAdd.m +// +// +// Created by guoyaoyuan on 13-4-5. +// Copyright (c) 2013 live Interactive. All rights reserved. +// + +#import "UIControl+YYAdd.h" +#import + + +static const int block_key; + +@interface _LFUIControlBlockTarget : NSObject + +@property (nonatomic, copy) void (^block)(id sender); +@property (nonatomic, assign) UIControlEvents events; + +- (id)initWithBlock:(void (^)(id sender))block events:(UIControlEvents)events; +- (void)invoke:(id)sender; + +@end + +@implementation _LFUIControlBlockTarget + +- (id)initWithBlock:(void (^)(id sender))block events:(UIControlEvents)events { + self = [super init]; + if (self) { + self.block = block; + self.events = events; + } + return self; +} + +- (void)invoke:(id)sender { + if (self.block) self.block(sender); +} + +@end + + + +@implementation UIControl (LFAdd) + +- (void)removeAllTargets { + [[self allTargets] enumerateObjectsUsingBlock: ^(id object, BOOL *stop) { + [self removeTarget:object + action:NULL + forControlEvents:UIControlEventAllEvents]; + }]; +} + +- (void)setTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents { + NSSet *targets = [self allTargets]; + for (id currentTarget in targets) { + NSArray *actions = [self actionsForTarget:currentTarget forControlEvent:controlEvents]; + for (NSString *currentAction in actions) { + [self removeTarget:currentTarget action:NSSelectorFromString(currentAction) + forControlEvents:controlEvents]; + } + } + [self addTarget:target action:action forControlEvents:controlEvents]; +} + +- (void)addBlockForControlEvents:(UIControlEvents)controlEvents + block:(void (^)(id sender))block { + _LFUIControlBlockTarget *target = [[_LFUIControlBlockTarget alloc] + initWithBlock:block events:controlEvents]; + [self addTarget:target action:@selector(invoke:) forControlEvents:controlEvents]; + NSMutableArray *targets = [self _lf_allUIControlBlockTargets]; + [targets addObject:target]; +} + +- (void)setBlockForControlEvents:(UIControlEvents)controlEvents + block:(void (^)(id sender))block { + [self removeAllBlocksForControlEvents:controlEvents]; + [self addBlockForControlEvents:controlEvents block:block]; +} + +- (void)removeAllBlocksForControlEvents:(UIControlEvents)controlEvents { + NSMutableArray *targets = [self _lf_allUIControlBlockTargets]; + NSMutableArray *removes = [NSMutableArray array]; + [targets enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) { + _LFUIControlBlockTarget *target = (_LFUIControlBlockTarget *)obj; + if (target.events == controlEvents) { + [removes addObject:target]; + [self removeTarget:target + action:@selector(invoke:) + forControlEvents:controlEvents]; + } + }]; + [targets removeObjectsInArray:removes]; +} + +- (NSMutableArray *)_lf_allUIControlBlockTargets { + NSMutableArray *targets = objc_getAssociatedObject(self, &block_key); + if (!targets) { + targets = [NSMutableArray array]; + objc_setAssociatedObject(self, &block_key, targets, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + } + return targets; +} + +@end diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/category/UIView+YYAdd.h b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/category/UIView+YYAdd.h new file mode 100644 index 00000000..8b49be66 --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/category/UIView+YYAdd.h @@ -0,0 +1,132 @@ +// +// UIView+Add.h +// +// +// Created by guoyaoyuan on 13-4-3. +// Copyright (c) 2013 live Interactive. All rights reserved. +// + +#import + +/** + Provides extensions for `UIView`. + */ +@interface UIView (YYAdd) + +/** + Create a snapshot image of the complete view hierarchy. + This method should be called in main thread. + */ +- (nullable UIImage *)snapshotImage; + +/** + Create a snapshot PDF of the complete view hierarchy. + This method should be called in main thread. + */ +- (nullable NSData *)snapshotPDF; + +/** + Shortcut to set the view.layer's shadow + + @param color Shadow Color + @param offset Shadow offset + @param radius Shadow radius + */ +- (void)setLayerShadow:(nullable UIColor*)color offset:(CGSize)offset radius:(CGFloat)radius; +/** + * 设置阴影 郭liyuan+ + */ +- (void) makeInsetShadow; +- (void) makeInsetShadowWithRadius:(float)radius Alpha:(float)alpha; +- (void) makeInsetShadowWithRadius:(float)radius Color:(nullable UIColor *)color Directions:(nullable NSArray *)directions; + +/** + Remove all subviews. + + @warning Never call this method inside your view's drawRect: method. + */ +- (void)removeAllSubviews; + +/** + Returns the view's view controller (may be nil). + */ +@property (nonatomic, readonly,nullable) UIViewController *viewController; + +@property (nonatomic) CGFloat left; ///< Shortcut for frame.origin.x. +@property (nonatomic) CGFloat top; ///< Shortcut for frame.origin.y +@property (nonatomic) CGFloat right; ///< Shortcut for frame.origin.x + frame.size.width +@property (nonatomic) CGFloat bottom; ///< Shortcut for frame.origin.y + frame.size.height +@property (nonatomic) CGFloat width; ///< Shortcut for frame.size.width. +@property (nonatomic) CGFloat height; ///< Shortcut for frame.size.height. +@property (nonatomic) CGFloat centerX; ///< Shortcut for center.x +@property (nonatomic) CGFloat centerY; ///< Shortcut for center.y +@property (nonatomic) CGPoint origin; ///< Shortcut for frame.origin. +@property (nonatomic) CGSize size; ///< Shortcut for frame.size. +@property (nonatomic, readonly) CGRect screenFrame; ///< View frame on the screen, taking into account scroll views. + +/** + Returns the visible alpha on screen, taking into account superview and window. + */ +@property (nonatomic, readonly) CGFloat visibleAlpha; + + +/** + Converts a point from the receiver's coordinate system to that of the specified view or window. + + @param point A point specified in the local coordinate system (bounds) of the receiver. + @param view The view or window into whose coordinate system point is to be converted. + If view is nil, this method instead converts to window base coordinates. + @return The point converted to the coordinate system of view. + */ +- (CGPoint)convertPoint:(CGPoint)point toViewOrWindow:(nullable UIView *)view; + +/** + Converts a point from the coordinate system of a given view or window to that of the receiver. + + @param point A point specified in the local coordinate system (bounds) of view. + @param view The view or window with point in its coordinate system. + If view is nil, this method instead converts from window base coordinates. + @return The point converted to the local coordinate system (bounds) of the receiver. + */ +- (CGPoint)convertPoint:(CGPoint)point fromViewOrWindow:(nullable UIView *)view; + +/** + Converts a rectangle from the receiver's coordinate system to that of another view or window. + + @param rect A rectangle specified in the local coordinate system (bounds) of the receiver. + @param view The view or window that is the target of the conversion operation. If view is nil, this method instead converts to window base coordinates. + @return The converted rectangle. + */ +- (CGRect)convertRect:(CGRect)rect toViewOrWindow:(nullable UIView *)view; + +/** + Converts a rectangle from the coordinate system of another view or window to that of the receiver. + + @param rect A rectangle specified in the local coordinate system (bounds) of view. + @param view The view or window with rect in its coordinate system. + If view is nil, this method instead converts from window base coordinates. + @return The converted rectangle. + */ +- (CGRect)convertRect:(CGRect)rect fromViewOrWindow:(nullable UIView *)view; + +/** + * 返回响应者链上的任意Objc + * + * @param viewControllerCls 需要返回的Obj的类名,为nil时默认返回当前控制器 + * + * @return viewController Or needCls + */ +- (nonnull id)viewControllerWithNeedViewOrViewController:(nullable Class)viewControllerCls +; + + +/// 移除所有子视图中 tableview、scrollview 的 delegate、datasource +- (void)clearScrollViewDelegate; + + +- (void)removeAllGestures; +- (void)removeAllGesturesWithSubViews; + +/// 在 block 内禁用动画 ++ (void)disableAnimationWithBlock:(nullable void (^)(void))block; +@end diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/category/UIView+YYAdd.m b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/category/UIView+YYAdd.m new file mode 100644 index 00000000..c4219033 --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/category/UIView+YYAdd.m @@ -0,0 +1,464 @@ +// +// UIView+Add.m +// +// +// Created by guoyaoyuan on 13-4-3. +// Copyright (c) 2013 live Interactive. All rights reserved. +// + +#import "UIView+YYAdd.h" +#import + +@implementation UIView (YYAdd) + +- (UIImage *)snapshotImage { + UIImage *image = nil; + if ([self respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) { + UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0); + [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES]; + image = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + }else{ + UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, 0); + [self.layer renderInContext:UIGraphicsGetCurrentContext()]; + image = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + } + return image; +} + +- (NSData *)snapshotPDF { + CGRect bounds = self.bounds; + NSMutableData* data = [NSMutableData data]; + CGDataConsumerRef consumer = CGDataConsumerCreateWithCFData((__bridge CFMutableDataRef)data); + CGContextRef context = CGPDFContextCreate(consumer, &bounds, NULL); + CGDataConsumerRelease(consumer); + if (!context) return nil; + CGPDFContextBeginPage(context, NULL); + CGContextTranslateCTM(context, 0, bounds.size.height); + CGContextScaleCTM(context, 1.0, -1.0); + [self.layer renderInContext:context]; + CGPDFContextEndPage(context); + CGPDFContextClose(context); + CGContextRelease(context); + return data; +} + +- (void)setLayerShadow:(UIColor*)color offset:(CGSize)offset radius:(CGFloat)radius { + self.layer.shadowColor = color.CGColor; + self.layer.shadowOffset = offset; + self.layer.shadowRadius = radius; + self.layer.shadowOpacity = 1; + self.layer.shouldRasterize = YES; + self.layer.rasterizationScale = [UIScreen mainScreen].scale; +} + + +#define kShadowViewTag 2132 +#define kValidDirections [NSArray arrayWithObjects: @"top", @"bottom", @"left", @"right",nil] + +- (void) makeInsetShadow +{ + NSArray *shadowDirections = [NSArray arrayWithObjects:@"top", @"bottom", @"left" , @"right" , nil]; + UIColor *color = [UIColor colorWithRed:(0.0) green:(0.0) blue:(0.0) alpha:0.5]; + + UIView *shadowView = [self createShadowViewWithRadius:3 Color:color Directions:shadowDirections]; + shadowView.tag = kShadowViewTag; + + [self addSubview:shadowView]; +} + +- (void) makeInsetShadowWithRadius:(float)radius Alpha:(float)alpha +{ + NSArray *shadowDirections = [NSArray arrayWithObjects:@"top", @"bottom", @"left" , @"right" , nil]; + UIColor *color = [UIColor colorWithRed:(0.0) green:(0.0) blue:(0.0) alpha:alpha]; + + UIView *shadowView = [self createShadowViewWithRadius:radius Color:color Directions:shadowDirections]; + shadowView.tag = kShadowViewTag; + + [self addSubview:shadowView]; +} + +- (void) makeInsetShadowWithRadius:(float)radius Color:(UIColor *)color Directions:(NSArray *)directions +{ + UIView *shadowView = [self createShadowViewWithRadius:radius Color:color Directions:directions]; + shadowView.tag = kShadowViewTag; + + [self addSubview:shadowView]; +} + +- (UIView *) createShadowViewWithRadius:(float)radius Color:(UIColor *)color Directions:(NSArray *)directions +{ + UIView *shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)]; + shadowView.backgroundColor = [UIColor clearColor]; + + // Ignore duplicate direction + NSMutableDictionary *directionDict = [[NSMutableDictionary alloc] init]; + for (NSString *direction in directions) [directionDict setObject:@"1" forKey:direction]; + +// for (NSString *direction in directionDict) { +// // Ignore invalid direction +// if ([kValidDirections containsObject:direction]) +// { +// CAGradientLayer *shadow = [CAGradientLayer layer]; +// shadow.locations = @[@(0.0),@(0.5)]; +// +// if ([direction isEqualToString:@"top"]) { +// [shadow setStartPoint:CGPointMake(0.5, 0.0)]; +// [shadow setEndPoint:CGPointMake(0.5, 1.0)]; +// shadow.frame = CGRectMake(-radius, -radius, self.bounds.size.width + radius*2, radius); +// shadow.colors = [NSArray arrayWithObjects:(id)[self.backgroundColor CGColor], (id)[color CGColor], nil]; +// } +// else if ([direction isEqualToString:@"bottom"]) +// { +// [shadow setStartPoint:CGPointMake(0.5, 1.0)]; +// [shadow setEndPoint:CGPointMake(0.5, 0.0)]; +// shadow.frame = CGRectMake(-radius, self.bounds.size.height, self.bounds.size.width + radius*2, radius); +// shadow.colors = [NSArray arrayWithObjects:(id)[self.backgroundColor CGColor] ,(id)[color CGColor], nil]; +// } else if ([direction isEqualToString:@"left"]) +// { +// shadow.frame = CGRectMake(-radius, -radius, radius, self.bounds.size.height + radius*2); +// [shadow setStartPoint:CGPointMake(0.0, 0.5)]; +// [shadow setEndPoint:CGPointMake(1.0, 0.5)]; +// shadow.colors = [NSArray arrayWithObjects:(id)[self.backgroundColor CGColor],(id)[color CGColor], nil]; +// +// } else if ([direction isEqualToString:@"right"]) +// { +// shadow.frame = CGRectMake(self.bounds.size.width, -radius, radius, self.bounds.size.height + radius*2); +// [shadow setStartPoint:CGPointMake(1.0, 0.5)]; +// [shadow setEndPoint:CGPointMake(0.0, 0.5)]; +// shadow.colors = [NSArray arrayWithObjects:(id)[self.backgroundColor CGColor],(id)[color CGColor], nil]; +// } +// // 后边一个颜色要和所加视图背景颜色一样 +// +// [shadowView.layer insertSublayer:shadow atIndex:0]; +// } +// } + + for (NSString *direction in directionDict) { + // Ignore invalid direction + if ([kValidDirections containsObject:direction]) + { + CALayer *shadow = [CAGradientLayer layer]; + shadow.backgroundColor = color.CGColor; + + if ([direction isEqualToString:@"top"]) { + shadow.frame = CGRectMake(0, 0, self.bounds.size.width, radius); + } + else if ([direction isEqualToString:@"bottom"]) + { + shadow.frame = CGRectMake(0, self.bounds.size.height, self.bounds.size.width, radius); + } else if ([direction isEqualToString:@"left"]) + { + shadow.frame = CGRectMake(0, 0, radius, self.bounds.size.height ); + } else if ([direction isEqualToString:@"right"]) + { + shadow.frame = CGRectMake(self.bounds.size.width, 0, radius, self.bounds.size.height); + } + [shadowView.layer insertSublayer:shadow atIndex:0]; + } + } + + + return shadowView; +} + + + +- (void)removeAllSubviews { + while (self.subviews.count) { + [self.subviews.lastObject removeFromSuperview]; + } +} + + +- (UIViewController *)viewController { + for (UIView *view = self; view; view = view.superview) { + UIResponder *nextResponder = [view nextResponder]; + if ([nextResponder isKindOfClass:[UIViewController class]]) { + return (UIViewController *)nextResponder; + } + } + return nil; +} + +- (nonnull id)viewControllerWithNeedViewOrViewController:(nullable Class)viewControllerCls +{ + UIViewController *result = nil; + + UIWindow * window = [[UIApplication sharedApplication] keyWindow]; + if (window.windowLevel != UIWindowLevelNormal) + { + NSArray *windows = [[UIApplication sharedApplication] windows]; + for(UIWindow * tmpWin in windows) + { + if (tmpWin.windowLevel == UIWindowLevelNormal) + { + window = tmpWin; + break; + } + } + } + + UIView *frontView = self; + id nextResponse = [frontView nextResponder]; + Class cls = viewControllerCls?viewControllerCls:UIViewController.class; + while (nextResponse) { + if ([nextResponse isKindOfClass:cls]) { + result = nextResponse; + break; + } + nextResponse = [nextResponse nextResponder]; + } + if(!result) result = window.rootViewController; + + return result; +} + + +- (CGFloat)left { + return self.frame.origin.x; +} + +- (void)setLeft:(CGFloat)x { + CGRect frame = self.frame; + frame.origin.x = x; + self.frame = frame; +} + +- (CGFloat)top { + return self.frame.origin.y; +} + +- (void)setTop:(CGFloat)y { + CGRect frame = self.frame; + frame.origin.y = y; + self.frame = frame; +} + +- (CGFloat)right { + return self.frame.origin.x + self.frame.size.width; +} + +- (void)setRight:(CGFloat)right { + CGRect frame = self.frame; + frame.origin.x = right - frame.size.width; + self.frame = frame; +} + +- (CGFloat)bottom { + return self.frame.origin.y + self.frame.size.height; +} + +- (void)setBottom:(CGFloat)bottom { + CGRect frame = self.frame; + frame.origin.y = bottom - frame.size.height; + self.frame = frame; +} + +- (CGFloat)width { + return self.frame.size.width; +} + +- (void)setWidth:(CGFloat)width { + CGRect frame = self.frame; + frame.size.width = width; + self.frame = frame; +} + +- (CGFloat)height { + return self.frame.size.height; +} + +- (void)setHeight:(CGFloat)height { + CGRect frame = self.frame; + frame.size.height = height; + self.frame = frame; +} + +- (CGFloat)centerX { + return self.center.x; +} + +- (void)setCenterX:(CGFloat)centerX { + self.center = CGPointMake(centerX, self.center.y); +} + +- (CGFloat)centerY { + return self.center.y; +} + +- (void)setCenterY:(CGFloat)centerY { + self.center = CGPointMake(self.center.x, centerY); +} + +- (CGPoint)origin { + return self.frame.origin; +} + +- (void)setOrigin:(CGPoint)origin { + CGRect frame = self.frame; + frame.origin = origin; + self.frame = frame; +} + +- (CGSize)size { + return self.frame.size; +} + +- (void)setSize:(CGSize)size { + CGRect frame = self.frame; + frame.size = size; + self.frame = frame; +} + +- (CGRect)screenFrame { + CGPoint origin = CGPointZero; + for (UIView *view = self; view; view = view.superview) { + origin.x += view.left; + origin.y += view.top; + + if ([view isKindOfClass:[UIScrollView class]]) { + UIScrollView *scrollView = (UIScrollView *)view; + origin.x -= scrollView.contentOffset.x; + origin.y -= scrollView.contentOffset.y; + } + } + return CGRectMake(origin.x, origin.y, self.width, self.height); +} + + +- (CGFloat)visibleAlpha { + if ([self isKindOfClass:[UIWindow class]]) { + if (self.hidden) return 0; + return self.alpha; + } + if (!self.window) return 0; + CGFloat alpha = 1; + UIView *v = self; + while (v) { + if (v.hidden) { + alpha = 0; + break; + } + alpha *= v.alpha; + v = v.superview; + } + return alpha; +} + + + +- (CGPoint)convertPoint:(CGPoint)point toViewOrWindow:(UIView *)view { + if (!view) { + if ([self isKindOfClass:[UIWindow class]]) { + return [((UIWindow *)self) convertPoint:point toWindow:nil]; + } else { + return [self convertPoint:point toView:nil]; + } + } + + UIWindow *from = [self isKindOfClass:[UIWindow class]] ? (id)self : self.window; + UIWindow *to = [view isKindOfClass:[UIWindow class]] ? (id)view : view.window; + if ((!from || !to) || (from == to)) return [self convertPoint:point toView:view]; + point = [self convertPoint:point toView:from]; + point = [to convertPoint:point fromWindow:from]; + point = [view convertPoint:point fromView:to]; + return point; +} + +- (CGPoint)convertPoint:(CGPoint)point fromViewOrWindow:(UIView *)view { + if (!view) { + if ([self isKindOfClass:[UIWindow class]]) { + return [((UIWindow *)self) convertPoint:point fromWindow:nil]; + } else { + return [self convertPoint:point fromView:nil]; + } + } + + UIWindow *from = [view isKindOfClass:[UIWindow class]] ? (id)view : view.window; + UIWindow *to = [self isKindOfClass:[UIWindow class]] ? (id)self : self.window; + if ((!from || !to) || (from == to)) return [self convertPoint:point fromView:view]; + point = [from convertPoint:point fromView:view]; + point = [to convertPoint:point fromWindow:from]; + point = [self convertPoint:point fromView:to]; + return point; +} + +- (CGRect)convertRect:(CGRect)rect toViewOrWindow:(UIView *)view { + if (!view) { + if ([self isKindOfClass:[UIWindow class]]) { + return [((UIWindow *)self) convertRect:rect toWindow:nil]; + } else { + return [self convertRect:rect toView:nil]; + } + } + + UIWindow *from = [self isKindOfClass:[UIWindow class]] ? (id)self : self.window; + UIWindow *to = [view isKindOfClass:[UIWindow class]] ? (id)view : view.window; + if (!from || !to) return [self convertRect:rect toView:view]; + if (from == to) return [self convertRect:rect toView:view]; + rect = [self convertRect:rect toView:from]; + rect = [to convertRect:rect fromWindow:from]; + rect = [view convertRect:rect fromView:to]; + return rect; +} + +- (CGRect)convertRect:(CGRect)rect fromViewOrWindow:(UIView *)view { + if (!view) { + if ([self isKindOfClass:[UIWindow class]]) { + return [((UIWindow *)self) convertRect:rect fromWindow:nil]; + } else { + return [self convertRect:rect fromView:nil]; + } + } + + UIWindow *from = [view isKindOfClass:[UIWindow class]] ? (id)view : view.window; + UIWindow *to = [self isKindOfClass:[UIWindow class]] ? (id)self : self.window; + if ((!from || !to) || (from == to)) return [self convertRect:rect fromView:view]; + rect = [from convertRect:rect fromView:view]; + rect = [to convertRect:rect fromWindow:from]; + rect = [self convertRect:rect fromView:to]; + return rect; +} + +- (void)clearScrollViewDelegate { + if ([self isKindOfClass:[UIScrollView class]]) { + ((UIScrollView *)self).delegate = nil; + if ([self isKindOfClass:[UITableView class]]) { + ((UITableView *)self).delegate = nil; + } + } + for (UIView *sub in self.subviews) { + [sub clearScrollViewDelegate]; + } +} + +- (void)removeAllGestures { + NSArray *gs = [self.gestureRecognizers copy]; + for (UIGestureRecognizer *g in gs) { + [self removeGestureRecognizer:g]; + } +} +- (void)removeAllGesturesWithSubViews { + [self removeAllGestures]; + for (UIView *v in self.subviews) { + [v removeAllGesturesWithSubViews]; + } + [UIView animateWithDuration:0 animations:^{ + + }]; +} + ++ (void)disableAnimationWithBlock:(void (^)(void))block { + if (!block) return; + BOOL aniEnabled = [CATransaction disableActions]; + [CATransaction setDisableActions:YES]; + block(); + [CATransaction setDisableActions:aniEnabled]; +} + + + +@end diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_beauty@2x.png b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_beauty@2x.png new file mode 100644 index 00000000..4e8a04a3 Binary files /dev/null and b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_beauty@2x.png differ diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_beauty@3x.png b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_beauty@3x.png new file mode 100644 index 00000000..acc63fbe Binary files /dev/null and b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_beauty@3x.png differ diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_beauty_close@2x.png b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_beauty_close@2x.png new file mode 100644 index 00000000..78a5bbfd Binary files /dev/null and b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_beauty_close@2x.png differ diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_beauty_close@3x.png b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_beauty_close@3x.png new file mode 100644 index 00000000..00e2402e Binary files /dev/null and b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_beauty_close@3x.png differ diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_preview@2x.png b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_preview@2x.png new file mode 100644 index 00000000..ddf8f655 Binary files /dev/null and b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_preview@2x.png differ diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_preview@3x.png b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_preview@3x.png new file mode 100644 index 00000000..c4cdc96b Binary files /dev/null and b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/camra_preview@3x.png differ diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/close_preview@2x.png b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/close_preview@2x.png new file mode 100644 index 00000000..af431dc7 Binary files /dev/null and b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/close_preview@2x.png differ diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/close_preview@3x.png b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/close_preview@3x.png new file mode 100644 index 00000000..b6a9203c Binary files /dev/null and b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/close_preview@3x.png differ diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/ios-29x29.png b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/ios-29x29.png new file mode 100644 index 00000000..03997000 Binary files /dev/null and b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/images/ios-29x29.png differ diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/main.m b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/main.m new file mode 100644 index 00000000..0f3c3d1f --- /dev/null +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo/main.m @@ -0,0 +1,16 @@ +// +// main.m +// LFLiveKitFrameworkDemo +// +// Created by admin on 2016/10/20. +// Copyright © 2016年 admin. All rights reserved. +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj new file mode 100644 index 00000000..1c7fc0bd --- /dev/null +++ b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj @@ -0,0 +1,435 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 5EA73C6322E98031301F2E03 /* Pods_LFLiveKitSwiftDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A28643F373DE90D96602753C /* Pods_LFLiveKitSwiftDemo.framework */; }; + 84D8B48C1D757D4000752B56 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B48B1D757D4000752B56 /* AppDelegate.swift */; }; + 84D8B48E1D757D4000752B56 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B48D1D757D4000752B56 /* ViewController.swift */; }; + 84D8B4911D757D4000752B56 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B48F1D757D4000752B56 /* Main.storyboard */; }; + 84D8B4931D757D4000752B56 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4921D757D4000752B56 /* Assets.xcassets */; }; + 84D8B4961D757D4000752B56 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4941D757D4000752B56 /* LaunchScreen.storyboard */; }; + 84D8B4AC1D757DBB00752B56 /* camra_beauty@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4A41D757DBB00752B56 /* camra_beauty@2x.png */; }; + 84D8B4AD1D757DBB00752B56 /* camra_beauty@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4A51D757DBB00752B56 /* camra_beauty@3x.png */; }; + 84D8B4AE1D757DBB00752B56 /* camra_beauty_close@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4A61D757DBB00752B56 /* camra_beauty_close@2x.png */; }; + 84D8B4AF1D757DBB00752B56 /* camra_beauty_close@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4A71D757DBB00752B56 /* camra_beauty_close@3x.png */; }; + 84D8B4B01D757DBB00752B56 /* camra_preview@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4A81D757DBB00752B56 /* camra_preview@2x.png */; }; + 84D8B4B11D757DBB00752B56 /* camra_preview@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4A91D757DBB00752B56 /* camra_preview@3x.png */; }; + 84D8B4B21D757DBB00752B56 /* close_preview@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4AA1D757DBB00752B56 /* close_preview@2x.png */; }; + 84D8B4B31D757DBB00752B56 /* close_preview@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4AB1D757DBB00752B56 /* close_preview@3x.png */; }; + 84D8B4BD1D757E0E00752B56 /* libstdc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D8B4BC1D757E0E00752B56 /* libstdc++.tbd */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 7265B07B4B6CEE8ECE8F7A63 /* 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 = ""; }; + 843592751DD30BF000811FC7 /* LFLiveKitSwiftDemo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LFLiveKitSwiftDemo-Bridging-Header.h"; sourceTree = ""; }; + 84D8B4881D757D4000752B56 /* LFLiveKitSwiftDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LFLiveKitSwiftDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 84D8B48B1D757D4000752B56 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 84D8B48D1D757D4000752B56 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 84D8B4901D757D4000752B56 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 84D8B4921D757D4000752B56 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 84D8B4951D757D4000752B56 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 84D8B4971D757D4000752B56 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 84D8B4A41D757DBB00752B56 /* camra_beauty@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty@2x.png"; sourceTree = ""; }; + 84D8B4A51D757DBB00752B56 /* camra_beauty@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty@3x.png"; sourceTree = ""; }; + 84D8B4A61D757DBB00752B56 /* camra_beauty_close@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty_close@2x.png"; sourceTree = ""; }; + 84D8B4A71D757DBB00752B56 /* camra_beauty_close@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty_close@3x.png"; sourceTree = ""; }; + 84D8B4A81D757DBB00752B56 /* camra_preview@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_preview@2x.png"; sourceTree = ""; }; + 84D8B4A91D757DBB00752B56 /* camra_preview@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_preview@3x.png"; sourceTree = ""; }; + 84D8B4AA1D757DBB00752B56 /* close_preview@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@2x.png"; sourceTree = ""; }; + 84D8B4AB1D757DBB00752B56 /* close_preview@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@3x.png"; sourceTree = ""; }; + 84D8B4BC1D757E0E00752B56 /* libstdc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libstdc++.tbd"; path = "usr/lib/libstdc++.tbd"; sourceTree = SDKROOT; }; + A28643F373DE90D96602753C /* Pods_LFLiveKitSwiftDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LFLiveKitSwiftDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + DAC498DB742E949DED005ECE /* 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 = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 84D8B4851D757D4000752B56 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 84D8B4BD1D757E0E00752B56 /* libstdc++.tbd in Frameworks */, + 5EA73C6322E98031301F2E03 /* Pods_LFLiveKitSwiftDemo.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 23FA2B0543E0C2A8E7C84D9E /* Frameworks */ = { + isa = PBXGroup; + children = ( + A28643F373DE90D96602753C /* Pods_LFLiveKitSwiftDemo.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 84D8B47F1D757D4000752B56 = { + isa = PBXGroup; + children = ( + 84D8B4BC1D757E0E00752B56 /* libstdc++.tbd */, + 84D8B48A1D757D4000752B56 /* LFLiveKitSwiftDemo */, + 84D8B4891D757D4000752B56 /* Products */, + B19B532AA669846CC85D50E3 /* Pods */, + 23FA2B0543E0C2A8E7C84D9E /* Frameworks */, + ); + sourceTree = ""; + }; + 84D8B4891D757D4000752B56 /* Products */ = { + isa = PBXGroup; + children = ( + 84D8B4881D757D4000752B56 /* LFLiveKitSwiftDemo.app */, + ); + name = Products; + sourceTree = ""; + }; + 84D8B48A1D757D4000752B56 /* LFLiveKitSwiftDemo */ = { + isa = PBXGroup; + children = ( + 84D8B48B1D757D4000752B56 /* AppDelegate.swift */, + 84D8B48D1D757D4000752B56 /* ViewController.swift */, + 843592751DD30BF000811FC7 /* LFLiveKitSwiftDemo-Bridging-Header.h */, + 84D8B48F1D757D4000752B56 /* Main.storyboard */, + 84D8B4A31D757DBB00752B56 /* images */, + 84D8B4921D757D4000752B56 /* Assets.xcassets */, + 84D8B4941D757D4000752B56 /* LaunchScreen.storyboard */, + 84D8B4971D757D4000752B56 /* Info.plist */, + ); + path = LFLiveKitSwiftDemo; + sourceTree = ""; + }; + 84D8B4A31D757DBB00752B56 /* images */ = { + isa = PBXGroup; + children = ( + 84D8B4A41D757DBB00752B56 /* camra_beauty@2x.png */, + 84D8B4A51D757DBB00752B56 /* camra_beauty@3x.png */, + 84D8B4A61D757DBB00752B56 /* camra_beauty_close@2x.png */, + 84D8B4A71D757DBB00752B56 /* camra_beauty_close@3x.png */, + 84D8B4A81D757DBB00752B56 /* camra_preview@2x.png */, + 84D8B4A91D757DBB00752B56 /* camra_preview@3x.png */, + 84D8B4AA1D757DBB00752B56 /* close_preview@2x.png */, + 84D8B4AB1D757DBB00752B56 /* close_preview@3x.png */, + ); + path = images; + sourceTree = ""; + }; + B19B532AA669846CC85D50E3 /* Pods */ = { + isa = PBXGroup; + children = ( + 7265B07B4B6CEE8ECE8F7A63 /* Pods-LFLiveKitSwiftDemo.debug.xcconfig */, + DAC498DB742E949DED005ECE /* Pods-LFLiveKitSwiftDemo.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 84D8B4871D757D4000752B56 /* LFLiveKitSwiftDemo */ = { + isa = PBXNativeTarget; + buildConfigurationList = 84D8B49A1D757D4000752B56 /* Build configuration list for PBXNativeTarget "LFLiveKitSwiftDemo" */; + buildPhases = ( + FC46EAD69B9F095AB7372DB6 /* 📦 Check Pods Manifest.lock */, + 84D8B4841D757D4000752B56 /* Sources */, + 84D8B4851D757D4000752B56 /* Frameworks */, + 84D8B4861D757D4000752B56 /* Resources */, + 951756CA4F11963EE3622ADB /* 📦 Embed Pods Frameworks */, + 1D8289CE7990A09D5E67FA15 /* 📦 Copy Pods Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = LFLiveKitSwiftDemo; + productName = LFLiveKitSwiftDemo; + productReference = 84D8B4881D757D4000752B56 /* LFLiveKitSwiftDemo.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 84D8B4801D757D4000752B56 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0730; + LastUpgradeCheck = 0730; + ORGANIZATIONNAME = admin; + TargetAttributes = { + 84D8B4871D757D4000752B56 = { + CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = G497YX6CBT; + LastSwiftMigration = 0800; + }; + }; + }; + buildConfigurationList = 84D8B4831D757D4000752B56 /* Build configuration list for PBXProject "LFLiveKitSwiftDemo" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 84D8B47F1D757D4000752B56; + productRefGroup = 84D8B4891D757D4000752B56 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 84D8B4871D757D4000752B56 /* LFLiveKitSwiftDemo */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 84D8B4861D757D4000752B56 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 84D8B4AE1D757DBB00752B56 /* camra_beauty_close@2x.png in Resources */, + 84D8B4961D757D4000752B56 /* LaunchScreen.storyboard in Resources */, + 84D8B4AC1D757DBB00752B56 /* camra_beauty@2x.png in Resources */, + 84D8B4931D757D4000752B56 /* Assets.xcassets in Resources */, + 84D8B4B11D757DBB00752B56 /* camra_preview@3x.png in Resources */, + 84D8B4AF1D757DBB00752B56 /* camra_beauty_close@3x.png in Resources */, + 84D8B4B31D757DBB00752B56 /* close_preview@3x.png in Resources */, + 84D8B4B21D757DBB00752B56 /* close_preview@2x.png in Resources */, + 84D8B4911D757D4000752B56 /* Main.storyboard in Resources */, + 84D8B4B01D757DBB00752B56 /* camra_preview@2x.png in Resources */, + 84D8B4AD1D757DBB00752B56 /* camra_beauty@3x.png in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 1D8289CE7990A09D5E67FA15 /* 📦 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-LFLiveKitSwiftDemo/Pods-LFLiveKitSwiftDemo-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; + 951756CA4F11963EE3622ADB /* 📦 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-LFLiveKitSwiftDemo/Pods-LFLiveKitSwiftDemo-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + FC46EAD69B9F095AB7372DB6 /* 📦 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 */ + 84D8B4841D757D4000752B56 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 84D8B48E1D757D4000752B56 /* ViewController.swift in Sources */, + 84D8B48C1D757D4000752B56 /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 84D8B48F1D757D4000752B56 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 84D8B4901D757D4000752B56 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 84D8B4941D757D4000752B56 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 84D8B4951D757D4000752B56 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 84D8B4981D757D4000752B56 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 84D8B4991D757D4000752B56 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 84D8B49B1D757D4000752B56 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7265B07B4B6CEE8ECE8F7A63 /* Pods-LFLiveKitSwiftDemo.debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = G497YX6CBT; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + HEADER_SEARCH_PATHS = "$(inherited)"; + INFOPLIST_FILE = LFLiveKitSwiftDemo/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = "$(inherited)"; + OTHER_LDFLAGS = "-all_load"; + PRODUCT_BUNDLE_IDENTIFIER = com.youku.LaiFeng; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "LFLiveKitSwiftDemo/LFLiveKitSwiftDemo-Bridging-Header.h"; + SWIFT_VERSION = 3.0; + }; + name = Debug; + }; + 84D8B49C1D757D4000752B56 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = DAC498DB742E949DED005ECE /* Pods-LFLiveKitSwiftDemo.release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = G497YX6CBT; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + HEADER_SEARCH_PATHS = "$(inherited)"; + INFOPLIST_FILE = LFLiveKitSwiftDemo/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = "$(inherited)"; + OTHER_LDFLAGS = "-all_load"; + PRODUCT_BUNDLE_IDENTIFIER = com.youku.LaiFeng; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "LFLiveKitSwiftDemo/LFLiveKitSwiftDemo-Bridging-Header.h"; + SWIFT_VERSION = 3.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 84D8B4831D757D4000752B56 /* Build configuration list for PBXProject "LFLiveKitSwiftDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 84D8B4981D757D4000752B56 /* Debug */, + 84D8B4991D757D4000752B56 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 84D8B49A1D757D4000752B56 /* Build configuration list for PBXNativeTarget "LFLiveKitSwiftDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 84D8B49B1D757D4000752B56 /* Debug */, + 84D8B49C1D757D4000752B56 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 84D8B4801D757D4000752B56 /* Project object */; +} diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/AppDelegate.swift b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/AppDelegate.swift new file mode 100644 index 00000000..cd6ef6ab --- /dev/null +++ b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/AppDelegate.swift @@ -0,0 +1,46 @@ +// +// AppDelegate.swift +// LFLiveKitSwiftDemo +// +// Created by admin on 16/8/30. +// Copyright © 2016年 admin. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + func applicationWillResignActive(_ application: UIApplication) { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + } + + func applicationDidEnterBackground(_ application: UIApplication) { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + } + + func applicationWillEnterForeground(_ application: UIApplication) { + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. + } + + func applicationDidBecomeActive(_ application: UIApplication) { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + } + + func applicationWillTerminate(_ application: UIApplication) { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + } + + +} + diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Assets.xcassets/AppIcon.appiconset/Contents.json b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..118c98f7 --- /dev/null +++ b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,38 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Base.lproj/LaunchScreen.storyboard b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 00000000..2e721e18 --- /dev/null +++ b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Base.lproj/Main.storyboard b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Base.lproj/Main.storyboard new file mode 100644 index 00000000..4e86a016 --- /dev/null +++ b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Base.lproj/Main.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LFLiveKitDemo/LFLiveKitDemo/Info.plist b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Info.plist similarity index 80% rename from LFLiveKitDemo/LFLiveKitDemo/Info.plist rename to samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Info.plist index 40c6215d..22b854f4 100644 --- a/LFLiveKitDemo/LFLiveKitDemo/Info.plist +++ b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/Info.plist @@ -26,6 +26,10 @@ LaunchScreen UIMainStoryboardFile Main + NSCameraUsageDescription + .. + NSMicrophoneUsageDescription + .. UIRequiredDeviceCapabilities armv7 @@ -36,12 +40,5 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight - UISupportedInterfaceOrientations~ipad - - UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo-Bridging-Header.h b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo-Bridging-Header.h new file mode 100644 index 00000000..251e8a97 --- /dev/null +++ b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo-Bridging-Header.h @@ -0,0 +1,14 @@ +// +// LFLiveKitSwiftDemo-Bridging-Header.h +// LFLiveKitSwiftDemo +// +// Created by admin on 2016/11/9. +// Copyright © 2016年 admin. All rights reserved. +// + +#ifndef LFLiveKitSwiftDemo_Bridging_Header_h +#define LFLiveKitSwiftDemo_Bridging_Header_h + +#import + +#endif /* LFLiveKitSwiftDemo_Bridging_Header_h */ diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/ViewController.swift b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/ViewController.swift new file mode 100644 index 00000000..931ff818 --- /dev/null +++ b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/ViewController.swift @@ -0,0 +1,215 @@ +// +// ViewController.swift +// LFLiveKitSwiftDemo +// +// Created by feng on 16/7/19. +// Copyright © 2016年 zhanqi.tv. All rights reserved. +// + +import UIKit +import LFLiveKit + +class ViewController: UIViewController, LFLiveSessionDelegate { + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view, typically from a nib. + + session.delegate = self + session.preView = self.view + + self.requestAccessForVideo() + self.requestAccessForAudio() + self.view.backgroundColor = UIColor.clear + self.view.addSubview(containerView) + containerView.addSubview(stateLabel) + containerView.addSubview(closeButton) + containerView.addSubview(beautyButton) + containerView.addSubview(cameraButton) + containerView.addSubview(startLiveButton) + + cameraButton.addTarget(self, action: #selector(didTappedCameraButton(_:)), for:.touchUpInside) + beautyButton.addTarget(self, action: #selector(didTappedBeautyButton(_:)), for: .touchUpInside) + startLiveButton.addTarget(self, action: #selector(didTappedStartLiveButton(_:)), for: .touchUpInside) + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + //MARK: AccessAuth + + func requestAccessForVideo() -> Void { + let status = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo); + switch status { + // 许可对话没有出现,发起授权许可 + case AVAuthorizationStatus.notDetermined: + AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (granted) in + if(granted){ + DispatchQueue.main.async { + self.session.running = true + } + } + }) + break; + // 已经开启授权,可继续 + case AVAuthorizationStatus.authorized: + session.running = true; + break; + // 用户明确地拒绝授权,或者相机设备无法访问 + case AVAuthorizationStatus.denied: break + case AVAuthorizationStatus.restricted:break; + default: + break; + } + } + + func requestAccessForAudio() -> Void { + let status = AVCaptureDevice.authorizationStatus(forMediaType:AVMediaTypeAudio) + switch status { + // 许可对话没有出现,发起授权许可 + case AVAuthorizationStatus.notDetermined: + AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeAudio, completionHandler: { (granted) in + + }) + break; + // 已经开启授权,可继续 + case AVAuthorizationStatus.authorized: + break; + // 用户明确地拒绝授权,或者相机设备无法访问 + case AVAuthorizationStatus.denied: break + case AVAuthorizationStatus.restricted:break; + default: + break; + } + } + + //MARK: - Callbacks + + // 回调 + func liveSession(_ session: LFLiveSession?, debugInfo: LFLiveDebug?) { + print("debugInfo: \(debugInfo?.currentBandwidth)") + } + + func liveSession(_ session: LFLiveSession?, errorCode: LFLiveSocketErrorCode) { + print("errorCode: \(errorCode.rawValue)") + } + + func liveSession(_ session: LFLiveSession?, liveStateDidChange state: LFLiveState) { + print("liveStateDidChange: \(state.rawValue)") + switch state { + case LFLiveState.ready: + stateLabel.text = "未连接" + break; + case LFLiveState.pending: + stateLabel.text = "连接中" + break; + case LFLiveState.start: + stateLabel.text = "已连接" + break; + case LFLiveState.error: + stateLabel.text = "连接错误" + break; + case LFLiveState.stop: + stateLabel.text = "未连接" + break; + default: + break; + } + } + + //MARK: - Events + + // 开始直播 + func didTappedStartLiveButton(_ button: UIButton) -> Void { + startLiveButton.isSelected = !startLiveButton.isSelected; + if (startLiveButton.isSelected) { + startLiveButton.setTitle("结束直播", for: UIControlState()) + let stream = LFLiveStreamInfo() + stream.url = "rtmp://live.hkstv.hk.lxdns.com:1935/live/stream153" + session.startLive(stream) + } else { + startLiveButton.setTitle("开始直播", for: UIControlState()) + session.stopLive() + } + } + + // 美颜 + func didTappedBeautyButton(_ button: UIButton) -> Void { + session.beautyFace = !session.beautyFace; + beautyButton.isSelected = !session.beautyFace + } + + // 摄像头 + func didTappedCameraButton(_ button: UIButton) -> Void { + let devicePositon = session.captureDevicePosition; + session.captureDevicePosition = (devicePositon == AVCaptureDevicePosition.back) ? AVCaptureDevicePosition.front : AVCaptureDevicePosition.back; + } + + // 关闭 + func didTappedCloseButton(_ button: UIButton) -> Void { + + } + + //MARK: - Getters and Setters + + //  默认分辨率368 * 640 音频:44.1 iphone6以上48 双声道 方向竖屏 + var session: LFLiveSession = { + let audioConfiguration = LFLiveAudioConfiguration.defaultConfiguration(for: LFLiveAudioQuality.high) + let videoConfiguration = LFLiveVideoConfiguration.defaultConfiguration(for: LFLiveVideoQuality.low3) + let session = LFLiveSession(audioConfiguration: audioConfiguration, videoConfiguration: videoConfiguration) + return session! + }() + + // 视图 + var containerView: UIView = { + let containerView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)) + containerView.backgroundColor = UIColor.clear + containerView.autoresizingMask = [UIViewAutoresizing.flexibleHeight, UIViewAutoresizing.flexibleHeight] + return containerView + }() + + // 状态Label + var stateLabel: UILabel = { + let stateLabel = UILabel(frame: CGRect(x: 20, y: 20, width: 80, height: 40)) + stateLabel.text = "未连接" + stateLabel.textColor = UIColor.white + stateLabel.font = UIFont.systemFont(ofSize: 14) + return stateLabel + }() + + // 关闭按钮 + var closeButton: UIButton = { + let closeButton = UIButton(frame: CGRect(x: UIScreen.main.bounds.width - 10 - 44, y: 20, width: 44, height: 44)) + closeButton.setImage(UIImage(named: "close_preview"), for: UIControlState()) + return closeButton + }() + + // 摄像头 + var cameraButton: UIButton = { + let cameraButton = UIButton(frame: CGRect(x: UIScreen.main.bounds.width - 54 * 2, y: 20, width: 44, height: 44)) + cameraButton.setImage(UIImage(named: "camra_preview"), for: UIControlState()) + return cameraButton + }() + + // 摄像头 + var beautyButton: UIButton = { + let beautyButton = UIButton(frame: CGRect(x: UIScreen.main.bounds.width - 54 * 3, y: 20, width: 44, height: 44)) + beautyButton.setImage(UIImage(named: "camra_beauty"), for: UIControlState.selected) + beautyButton.setImage(UIImage(named: "camra_beauty_close"), for: UIControlState()) + return beautyButton + }() + + // 开始直播按钮 + var startLiveButton: UIButton = { + let startLiveButton = UIButton(frame: CGRect(x: 30, y: UIScreen.main.bounds.height - 50, width: UIScreen.main.bounds.width - 10 - 44, height: 44)) + startLiveButton.layer.cornerRadius = 22 + startLiveButton.setTitleColor(UIColor.black, for:UIControlState()) + startLiveButton.setTitle("开始直播", for: UIControlState()) + startLiveButton.titleLabel!.font = UIFont.systemFont(ofSize: 14) + startLiveButton.backgroundColor = UIColor(colorLiteralRed: 50, green: 32, blue: 245, alpha: 1) + return startLiveButton + }() +} + diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_beauty@2x.png b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_beauty@2x.png new file mode 100644 index 00000000..4e8a04a3 Binary files /dev/null and b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_beauty@2x.png differ diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_beauty@3x.png b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_beauty@3x.png new file mode 100644 index 00000000..acc63fbe Binary files /dev/null and b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_beauty@3x.png differ diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_beauty_close@2x.png b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_beauty_close@2x.png new file mode 100644 index 00000000..78a5bbfd Binary files /dev/null and b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_beauty_close@2x.png differ diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_beauty_close@3x.png b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_beauty_close@3x.png new file mode 100644 index 00000000..00e2402e Binary files /dev/null and b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_beauty_close@3x.png differ diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_preview@2x.png b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_preview@2x.png new file mode 100644 index 00000000..ddf8f655 Binary files /dev/null and b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_preview@2x.png differ diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_preview@3x.png b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_preview@3x.png new file mode 100644 index 00000000..c4cdc96b Binary files /dev/null and b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/camra_preview@3x.png differ diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/close_preview@2x.png b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/close_preview@2x.png new file mode 100644 index 00000000..af431dc7 Binary files /dev/null and b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/close_preview@2x.png differ diff --git a/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/close_preview@3x.png b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/close_preview@3x.png new file mode 100644 index 00000000..b6a9203c Binary files /dev/null and b/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/images/close_preview@3x.png differ diff --git a/samples/LFLiveKitSwiftDemo/Podfile b/samples/LFLiveKitSwiftDemo/Podfile new file mode 100644 index 00000000..9883348e --- /dev/null +++ b/samples/LFLiveKitSwiftDemo/Podfile @@ -0,0 +1,8 @@ +source 'https://github.com/CocoaPods/Specs.git' +platform :ios,'7.0' + +use_frameworks! + +target “LFLiveKitSwiftDemo” do + pod 'LFLiveKit', :path => '../../.' +end diff --git a/scripts/build-universal-framework.sh b/scripts/build-universal-framework.sh new file mode 100755 index 00000000..36f56935 --- /dev/null +++ b/scripts/build-universal-framework.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +UNIVERSAL_OUTPUT_FOLDER="${PROJECT_DIR}/build/" + +# make the output directory and delete the framework directory +mkdir -p "${UNIVERSAL_OUTPUT_FOLDER}" +rm -rf "${UNIVERSAL_OUTPUT_FOLDER}/${PROJECT_NAME}.framework" + +# Step 1. Build Device and Simulator versions +xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build +xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build + +# Step 2. Copy the framework structure to the universal folder +echo "==============Step 2==============" +echo "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" + +cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUT_FOLDER}/" + +# Step 3. Create universal binary file using lipo and place the combined executable in the copied framework directory +lipo -create -output "${UNIVERSAL_OUTPUT_FOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}" + +echo "==============Completion==============" +echo "${UNIVERSAL_OUTPUT_FOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" + +# Step 4. Copy strings bundle if exists +STRINGS_INPUT_FOLDER="${PROJECT_NAME}Strings.bundle" +if [ -d "${STRINGS_INPUT_FOLDER}" ]; then +STRINGS_OUTPUT_FOLDER="${UNIVERSAL_OUTPUT_FOLDER}/${PROJECT_NAME}Strings.bundle" +rm -rf "${STRINGS_OUTPUT_FOLDER}" +cp -R "${STRINGS_INPUT_FOLDER}" "${STRINGS_OUTPUT_FOLDER}" +fi \ No newline at end of file