diff --git a/FrameWork/Info.plist b/FrameWork/Info.plist index c623d5e8..4fe33001 100644 --- a/FrameWork/Info.plist +++ b/FrameWork/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.4.3 + 2.5 CFBundleSignature ???? CFBundleVersion diff --git a/FrameWork/LFLiveKit.xcodeproj/project.pbxproj b/FrameWork/LFLiveKit.xcodeproj/project.pbxproj index 702df2dd..db20eadc 100644 --- a/FrameWork/LFLiveKit.xcodeproj/project.pbxproj +++ b/FrameWork/LFLiveKit.xcodeproj/project.pbxproj @@ -22,6 +22,368 @@ /* 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 */; }; 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 */; }; @@ -136,6 +498,368 @@ /* 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 = ""; }; @@ -220,6 +944,407 @@ /* 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 = ( @@ -267,6 +1392,7 @@ 84D8B5A71D768B6E00752B56 /* LFLiveSession.m */, 84D8B5A81D768B6E00752B56 /* objects */, 84D8B5B31D768B6E00752B56 /* publish */, + 84358E851DD1FEB500811FC7 /* Vendor */, ); name = LFLiveKit; path = ../LFLiveKit; @@ -415,31 +1541,215 @@ 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; }; @@ -597,28 +1907,206 @@ 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; }; @@ -644,14 +2132,8 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_SEARCH_PATHS = ( - "\"$(SRCROOT)/../samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework\"", - "\"$(SRCROOT)/../samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework\"", - ); - HEADER_SEARCH_PATHS = ( - "\"$(SRCROOT)/../samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers\"", - "\"$(SRCROOT)/../samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers\"", - ); + FRAMEWORK_SEARCH_PATHS = ""; + HEADER_SEARCH_PATHS = ""; INFOPLIST_FILE = LFLiveKitFramework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -675,14 +2157,8 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_SEARCH_PATHS = ( - "\"$(SRCROOT)/../samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework\"", - "\"$(SRCROOT)/../samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework\"", - ); - HEADER_SEARCH_PATHS = ( - "\"$(SRCROOT)/../samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers\"", - "\"$(SRCROOT)/../samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers\"", - ); + FRAMEWORK_SEARCH_PATHS = ""; + HEADER_SEARCH_PATHS = ""; INFOPLIST_FILE = LFLiveKitFramework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; diff --git a/LFLiveKit.podspec b/LFLiveKit.podspec index af296e3a..b7a7388f 100644 --- a/LFLiveKit.podspec +++ b/LFLiveKit.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = "LFLiveKit" - s.version = "2.4.3" + s.version = "2.5" s.summary = "LaiFeng ios Live. LFLiveKit." s.homepage = "https://github.com/chenliming777" s.license = { :type => "MIT", :file => "LICENSE" } @@ -17,6 +17,4 @@ Pod::Spec.new do |s| s.libraries = "c++", "z" s.requires_arc = true - s.dependency 'LMGPUImage' - s.dependency 'pili-librtmp', '1.0.3.1' end diff --git a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GLProgram.h b/LFLiveKit/Vendor/GPUImage/GLProgram.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GLProgram.h rename to LFLiveKit/Vendor/GPUImage/GLProgram.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImage.h b/LFLiveKit/Vendor/GPUImage/GPUImage.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImage.h rename to LFLiveKit/Vendor/GPUImage/GPUImage.h diff --git a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImage3x3ConvolutionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImage3x3ConvolutionFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImage3x3ConvolutionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImage3x3ConvolutionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImage3x3TextureSamplingFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImage3x3TextureSamplingFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImage3x3TextureSamplingFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImage3x3TextureSamplingFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageAdaptiveThresholdFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageAdaptiveThresholdFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageAdaptiveThresholdFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageAdaptiveThresholdFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageAddBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageAddBlendFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageAddBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageAddBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageAlphaBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageAlphaBlendFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageAlphaBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageAlphaBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageAmatorkaFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageAmatorkaFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageAmatorkaFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageAmatorkaFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageAverageColor.h b/LFLiveKit/Vendor/GPUImage/GPUImageAverageColor.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageAverageColor.h rename to LFLiveKit/Vendor/GPUImage/GPUImageAverageColor.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageAverageLuminanceThresholdFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageAverageLuminanceThresholdFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageAverageLuminanceThresholdFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageAverageLuminanceThresholdFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageBilateralFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageBilateralFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageBilateralFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageBilateralFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageBoxBlurFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageBoxBlurFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageBoxBlurFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageBoxBlurFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageBrightnessFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageBrightnessFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageBrightnessFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageBrightnessFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageBuffer.h b/LFLiveKit/Vendor/GPUImage/GPUImageBuffer.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageBuffer.h rename to LFLiveKit/Vendor/GPUImage/GPUImageBuffer.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageBulgeDistortionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageBulgeDistortionFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageBulgeDistortionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageBulgeDistortionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageCGAColorspaceFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageCGAColorspaceFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageCGAColorspaceFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageCGAColorspaceFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageCannyEdgeDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageCannyEdgeDetectionFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageCannyEdgeDetectionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageCannyEdgeDetectionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageChromaKeyBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyBlendFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageChromaKeyBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageChromaKeyFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageChromaKeyFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageClosingFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageClosingFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageClosingFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageClosingFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorBlendFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageColorBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorBurnBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorBurnBlendFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorBurnBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageColorBurnBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorConversion.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorConversion.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorConversion.h rename to LFLiveKit/Vendor/GPUImage/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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorDodgeBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorDodgeBlendFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorDodgeBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageColorDodgeBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorInvertFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorInvertFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorInvertFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageColorInvertFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorLocalBinaryPatternFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorLocalBinaryPatternFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorLocalBinaryPatternFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageColorLocalBinaryPatternFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorMatrixFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorMatrixFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorMatrixFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageColorMatrixFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorPackingFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorPackingFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColorPackingFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageColorPackingFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColourFASTFeatureDetector.h b/LFLiveKit/Vendor/GPUImage/GPUImageColourFASTFeatureDetector.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColourFASTFeatureDetector.h rename to LFLiveKit/Vendor/GPUImage/GPUImageColourFASTFeatureDetector.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColourFASTSamplingOperation.h b/LFLiveKit/Vendor/GPUImage/GPUImageColourFASTSamplingOperation.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageColourFASTSamplingOperation.h rename to LFLiveKit/Vendor/GPUImage/GPUImageColourFASTSamplingOperation.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageContrastFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageContrastFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageContrastFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageContrastFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageCropFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageCropFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageCropFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageCropFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageCrosshairGenerator.h b/LFLiveKit/Vendor/GPUImage/GPUImageCrosshairGenerator.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageCrosshairGenerator.h rename to LFLiveKit/Vendor/GPUImage/GPUImageCrosshairGenerator.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageCrosshatchFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageCrosshatchFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageCrosshatchFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageCrosshatchFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageDarkenBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageDarkenBlendFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageDarkenBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageDarkenBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageDifferenceBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageDifferenceBlendFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageDifferenceBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageDifferenceBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageDilationFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageDilationFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageDilationFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageDilationFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageDirectionalNonMaximumSuppressionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageDirectionalNonMaximumSuppressionFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageDirectionalNonMaximumSuppressionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageDirectionalNonMaximumSuppressionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageDirectionalSobelEdgeDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageDirectionalSobelEdgeDetectionFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageDirectionalSobelEdgeDetectionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageDirectionalSobelEdgeDetectionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageDissolveBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageDissolveBlendFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageDissolveBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageDissolveBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageDivideBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageDivideBlendFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageDivideBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageDivideBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageEmbossFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageEmbossFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageEmbossFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageEmbossFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageErosionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageErosionFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageErosionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageErosionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageExclusionBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageExclusionBlendFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageExclusionBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageExclusionBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageExposureFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageExposureFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageExposureFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageExposureFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFASTCornerDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageFASTCornerDetectionFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFASTCornerDetectionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageFASTCornerDetectionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFalseColorFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageFalseColorFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFalseColorFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageFalseColorFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFilterGroup.h b/LFLiveKit/Vendor/GPUImage/GPUImageFilterGroup.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFilterGroup.h rename to LFLiveKit/Vendor/GPUImage/GPUImageFilterGroup.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFilterPipeline.h b/LFLiveKit/Vendor/GPUImage/GPUImageFilterPipeline.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFilterPipeline.h rename to LFLiveKit/Vendor/GPUImage/GPUImageFilterPipeline.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFourInputFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageFourInputFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFourInputFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageFourInputFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFramebuffer.h b/LFLiveKit/Vendor/GPUImage/GPUImageFramebuffer.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFramebuffer.h rename to LFLiveKit/Vendor/GPUImage/GPUImageFramebuffer.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFramebufferCache.h b/LFLiveKit/Vendor/GPUImage/GPUImageFramebufferCache.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFramebufferCache.h rename to LFLiveKit/Vendor/GPUImage/GPUImageFramebufferCache.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageGammaFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageGammaFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageGammaFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageGammaFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageGaussianBlurFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageGaussianBlurFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageGaussianBlurPositionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurPositionFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageGaussianBlurPositionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurPositionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageGaussianSelectiveBlurFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageGaussianSelectiveBlurFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageGaussianSelectiveBlurFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageGaussianSelectiveBlurFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageGlassSphereFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageGlassSphereFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageGlassSphereFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageGlassSphereFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageGrayscaleFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageGrayscaleFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageGrayscaleFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageGrayscaleFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHSBFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHSBFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHSBFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageHSBFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHalftoneFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHalftoneFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHalftoneFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageHalftoneFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHardLightBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHardLightBlendFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHardLightBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageHardLightBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHarrisCornerDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHarrisCornerDetectionFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHarrisCornerDetectionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageHarrisCornerDetectionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHazeFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHazeFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHazeFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageHazeFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHighPassFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHighPassFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHighPassFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageHighPassFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHighlightShadowFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHighlightShadowFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHighlightShadowFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageHighlightShadowFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHistogramEqualizationFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHistogramEqualizationFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHistogramEqualizationFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageHistogramEqualizationFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHistogramFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHistogramFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHistogramFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageHistogramFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHistogramGenerator.h b/LFLiveKit/Vendor/GPUImage/GPUImageHistogramGenerator.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHistogramGenerator.h rename to LFLiveKit/Vendor/GPUImage/GPUImageHistogramGenerator.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHoughTransformLineDetector.h b/LFLiveKit/Vendor/GPUImage/GPUImageHoughTransformLineDetector.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHoughTransformLineDetector.h rename to LFLiveKit/Vendor/GPUImage/GPUImageHoughTransformLineDetector.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHueBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHueBlendFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHueBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageHueBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHueFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHueFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageHueFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageHueFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageJFAVoronoiFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageJFAVoronoiFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageJFAVoronoiFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageJFAVoronoiFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageKuwaharaFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageKuwaharaFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageKuwaharaRadius3Filter.h b/LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaRadius3Filter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageKuwaharaRadius3Filter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaRadius3Filter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLanczosResamplingFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLanczosResamplingFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLanczosResamplingFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageLanczosResamplingFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLaplacianFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLaplacianFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLaplacianFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageLaplacianFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLevelsFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLevelsFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLevelsFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageLevelsFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLightenBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLightenBlendFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLightenBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageLightenBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLineGenerator.h b/LFLiveKit/Vendor/GPUImage/GPUImageLineGenerator.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLineGenerator.h rename to LFLiveKit/Vendor/GPUImage/GPUImageLineGenerator.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLinearBurnBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLinearBurnBlendFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLinearBurnBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageLinearBurnBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLocalBinaryPatternFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLocalBinaryPatternFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLocalBinaryPatternFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageLocalBinaryPatternFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLookupFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLookupFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLookupFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageLookupFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLowPassFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLowPassFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLowPassFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageLowPassFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLuminanceRangeFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLuminanceRangeFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLuminanceRangeFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageLuminanceRangeFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLuminanceThresholdFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLuminanceThresholdFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLuminanceThresholdFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageLuminanceThresholdFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLuminosity.h b/LFLiveKit/Vendor/GPUImage/GPUImageLuminosity.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLuminosity.h rename to LFLiveKit/Vendor/GPUImage/GPUImageLuminosity.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLuminosityBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLuminosityBlendFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageLuminosityBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageLuminosityBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMaskFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageMaskFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMaskFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageMaskFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMedianFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageMedianFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMedianFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageMedianFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMissEtikateFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageMissEtikateFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMissEtikateFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageMissEtikateFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMonochromeFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageMonochromeFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMonochromeFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageMonochromeFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMosaicFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageMosaicFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMosaicFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageMosaicFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMotionBlurFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageMotionBlurFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMotionBlurFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageMotionBlurFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMotionDetector.h b/LFLiveKit/Vendor/GPUImage/GPUImageMotionDetector.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMotionDetector.h rename to LFLiveKit/Vendor/GPUImage/GPUImageMotionDetector.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMovie.h b/LFLiveKit/Vendor/GPUImage/GPUImageMovie.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMovie.h rename to LFLiveKit/Vendor/GPUImage/GPUImageMovie.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMovieComposition.h b/LFLiveKit/Vendor/GPUImage/GPUImageMovieComposition.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMovieComposition.h rename to LFLiveKit/Vendor/GPUImage/GPUImageMovieComposition.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMultiplyBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageMultiplyBlendFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMultiplyBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageMultiplyBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageNobleCornerDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageNobleCornerDetectionFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageNobleCornerDetectionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageNobleCornerDetectionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageNonMaximumSuppressionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageNonMaximumSuppressionFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageNonMaximumSuppressionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageNonMaximumSuppressionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageNormalBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageNormalBlendFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageNormalBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageNormalBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageOpacityFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageOpacityFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageOpacityFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageOpacityFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageOpeningFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageOpeningFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageOpeningFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageOpeningFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageOutput.h b/LFLiveKit/Vendor/GPUImage/GPUImageOutput.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageOutput.h rename to LFLiveKit/Vendor/GPUImage/GPUImageOutput.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageOverlayBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageOverlayBlendFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageOverlayBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageOverlayBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageParallelCoordinateLineTransformFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageParallelCoordinateLineTransformFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageParallelCoordinateLineTransformFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageParallelCoordinateLineTransformFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePerlinNoiseFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePerlinNoiseFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePerlinNoiseFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImagePerlinNoiseFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePinchDistortionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePinchDistortionFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePinchDistortionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImagePinchDistortionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePixellateFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePixellateFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePixellateFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImagePixellateFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePixellatePositionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePixellatePositionFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePixellatePositionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImagePixellatePositionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePoissonBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePoissonBlendFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePoissonBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImagePoissonBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePolarPixellateFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePolarPixellateFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePolarPixellateFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImagePolarPixellateFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePolkaDotFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePolkaDotFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePolkaDotFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImagePolkaDotFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePosterizeFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePosterizeFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePosterizeFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImagePosterizeFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePrewittEdgeDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePrewittEdgeDetectionFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePrewittEdgeDetectionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImagePrewittEdgeDetectionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageRGBClosingFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageRGBClosingFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageRGBClosingFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageRGBClosingFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageRGBDilationFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageRGBDilationFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageRGBDilationFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageRGBDilationFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageRGBErosionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageRGBErosionFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageRGBErosionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageRGBErosionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageRGBFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageRGBFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageRGBFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageRGBFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageRGBOpeningFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageRGBOpeningFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageRGBOpeningFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageRGBOpeningFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageRawDataInput.h b/LFLiveKit/Vendor/GPUImage/GPUImageRawDataInput.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageRawDataInput.h rename to LFLiveKit/Vendor/GPUImage/GPUImageRawDataInput.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageRawDataOutput.h b/LFLiveKit/Vendor/GPUImage/GPUImageRawDataOutput.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageRawDataOutput.h rename to LFLiveKit/Vendor/GPUImage/GPUImageRawDataOutput.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSaturationBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSaturationBlendFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSaturationBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSaturationBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSaturationFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSaturationFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSaturationFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSaturationFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageScreenBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageScreenBlendFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageScreenBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageScreenBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSepiaFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSepiaFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSepiaFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSepiaFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSharpenFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSharpenFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSharpenFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSharpenFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageShiTomasiFeatureDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageShiTomasiFeatureDetectionFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageShiTomasiFeatureDetectionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageShiTomasiFeatureDetectionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSingleComponentGaussianBlurFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSingleComponentGaussianBlurFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSingleComponentGaussianBlurFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSingleComponentGaussianBlurFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSketchFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSketchFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSketchFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSketchFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSmoothToonFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSmoothToonFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSmoothToonFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSmoothToonFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSobelEdgeDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSobelEdgeDetectionFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSobelEdgeDetectionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSobelEdgeDetectionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSoftEleganceFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSoftEleganceFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSoftEleganceFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSoftEleganceFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSoftLightBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSoftLightBlendFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSoftLightBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSoftLightBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSolarizeFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSolarizeFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSolarizeFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSolarizeFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSolidColorGenerator.h b/LFLiveKit/Vendor/GPUImage/GPUImageSolidColorGenerator.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSolidColorGenerator.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSolidColorGenerator.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSourceOverBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSourceOverBlendFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSourceOverBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSourceOverBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSphereRefractionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSphereRefractionFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSphereRefractionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSphereRefractionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageStillCamera.h b/LFLiveKit/Vendor/GPUImage/GPUImageStillCamera.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageStillCamera.h rename to LFLiveKit/Vendor/GPUImage/GPUImageStillCamera.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageStretchDistortionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageStretchDistortionFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageStretchDistortionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageStretchDistortionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSubtractBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSubtractBlendFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSubtractBlendFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSubtractBlendFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSwirlFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSwirlFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageSwirlFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageSwirlFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTextureInput.h b/LFLiveKit/Vendor/GPUImage/GPUImageTextureInput.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTextureInput.h rename to LFLiveKit/Vendor/GPUImage/GPUImageTextureInput.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTextureOutput.h b/LFLiveKit/Vendor/GPUImage/GPUImageTextureOutput.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTextureOutput.h rename to LFLiveKit/Vendor/GPUImage/GPUImageTextureOutput.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageThreeInputFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageThreeInputFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageThreeInputFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageThreeInputFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageThresholdEdgeDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageThresholdEdgeDetectionFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageThresholdEdgeDetectionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageThresholdEdgeDetectionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageThresholdSketchFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageThresholdSketchFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageThresholdSketchFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageThresholdSketchFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageThresholdedNonMaximumSuppressionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageThresholdedNonMaximumSuppressionFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageThresholdedNonMaximumSuppressionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageThresholdedNonMaximumSuppressionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTiltShiftFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageTiltShiftFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTiltShiftFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageTiltShiftFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageToneCurveFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageToneCurveFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageToneCurveFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageToneCurveFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageToonFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageToonFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageToonFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageToonFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTransformFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageTransformFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTransformFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageTransformFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTwoInputCrossTextureSamplingFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageTwoInputCrossTextureSamplingFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTwoInputCrossTextureSamplingFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageTwoInputCrossTextureSamplingFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTwoInputFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageTwoInputFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTwoInputFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageTwoInputFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTwoPassFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageTwoPassFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTwoPassFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageTwoPassFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTwoPassTextureSamplingFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageTwoPassTextureSamplingFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageTwoPassTextureSamplingFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageTwoPassTextureSamplingFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageUIElement.h b/LFLiveKit/Vendor/GPUImage/GPUImageUIElement.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageUIElement.h rename to LFLiveKit/Vendor/GPUImage/GPUImageUIElement.h diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageUIElement.m b/LFLiveKit/Vendor/GPUImage/GPUImageUIElement.m new file mode 100644 index 00000000..33208924 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageUIElement.m @@ -0,0 +1,123 @@ +#import "GPUImageUIElement.h" + +@interface GPUImageUIElement () +{ + UIView *view; + CALayer *layer; + + CGSize previousLayerSizeInPixels; + CMTime time; + NSTimeInterval actualTimeOfLastUpdate; +} + +@end + +@implementation GPUImageUIElement + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithView:(UIView *)inputView; +{ + if (!(self = [super init])) + { + return nil; + } + + view = inputView; + layer = inputView.layer; + + previousLayerSizeInPixels = CGSizeZero; + [self update]; + + return self; +} + +- (id)initWithLayer:(CALayer *)inputLayer; +{ + if (!(self = [super init])) + { + return nil; + } + + view = nil; + layer = inputLayer; + + previousLayerSizeInPixels = CGSizeZero; + [self update]; + + return self; +} + +#pragma mark - +#pragma mark Layer management + +- (CGSize)layerSizeInPixels; +{ + CGSize pointSize = layer.bounds.size; + return CGSizeMake(layer.contentsScale * pointSize.width, layer.contentsScale * pointSize.height); +} + +- (void)update; +{ + [self updateWithTimestamp:kCMTimeIndefinite]; +} + +- (void)updateUsingCurrentTime; +{ + if(CMTIME_IS_INVALID(time)) { + time = CMTimeMakeWithSeconds(0, 600); + actualTimeOfLastUpdate = [NSDate timeIntervalSinceReferenceDate]; + } else { + NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate]; + NSTimeInterval diff = now - actualTimeOfLastUpdate; + time = CMTimeAdd(time, CMTimeMakeWithSeconds(diff, 600)); + actualTimeOfLastUpdate = now; + } + + [self updateWithTimestamp:time]; +} + +- (void)updateWithTimestamp:(CMTime)frameTime; +{ + [GPUImageContext useImageProcessingContext]; + + CGSize layerPixelSize = [self layerSizeInPixels]; + + GLubyte *imageData = (GLubyte *) calloc(1, (int)layerPixelSize.width * (int)layerPixelSize.height * 4); + + CGColorSpaceRef genericRGBColorspace = CGColorSpaceCreateDeviceRGB(); + CGContextRef imageContext = CGBitmapContextCreate(imageData, (int)layerPixelSize.width, (int)layerPixelSize.height, 8, (int)layerPixelSize.width * 4, genericRGBColorspace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst); +// CGContextRotateCTM(imageContext, M_PI_2); + CGContextTranslateCTM(imageContext, 0.0f, layerPixelSize.height); + CGContextScaleCTM(imageContext, layer.contentsScale, -layer.contentsScale); + // CGContextSetBlendMode(imageContext, kCGBlendModeCopy); // From Technical Q&A QA1708: http://developer.apple.com/library/ios/#qa/qa1708/_index.html + + [layer renderInContext:imageContext]; + + CGContextRelease(imageContext); + CGColorSpaceRelease(genericRGBColorspace); + + // TODO: This may not work + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:layerPixelSize textureOptions:self.outputTextureOptions onlyTexture:YES]; + + glBindTexture(GL_TEXTURE_2D, [outputFramebuffer texture]); + // no need to use self.outputTextureOptions here, we always need these texture options + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (int)layerPixelSize.width, (int)layerPixelSize.height, 0, GL_BGRA, GL_UNSIGNED_BYTE, imageData); + + free(imageData); + + for (id currentTarget in targets) + { + if (currentTarget != self.targetToIgnoreForUpdates) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger textureIndexOfTarget = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + + [currentTarget setInputSize:layerPixelSize atIndex:textureIndexOfTarget]; + [currentTarget newFrameReadyAtTime:frameTime atIndex:textureIndexOfTarget]; + } + } +} + +@end diff --git a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageUnsharpMaskFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageUnsharpMaskFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageUnsharpMaskFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageUnsharpMaskFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageVideoCamera.h b/LFLiveKit/Vendor/GPUImage/GPUImageVideoCamera.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageVideoCamera.h rename to LFLiveKit/Vendor/GPUImage/GPUImageVideoCamera.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageVignetteFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageVignetteFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageVignetteFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageVignetteFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageVoronoiConsumerFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageVoronoiConsumerFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageVoronoiConsumerFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageVoronoiConsumerFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageWeakPixelInclusionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageWeakPixelInclusionFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageWeakPixelInclusionFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageWeakPixelInclusionFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageWhiteBalanceFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageWhiteBalanceFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageWhiteBalanceFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageWhiteBalanceFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageXYDerivativeFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageXYDerivativeFilter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageXYDerivativeFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageXYDerivativeFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageZoomBlurFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageZoomBlurFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageZoomBlurFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageZoomBlurFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageiOSBlurFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageiOSBlurFilter.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageiOSBlurFilter.h rename to LFLiveKit/Vendor/GPUImage/GPUImageiOSBlurFilter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFramework.h b/LFLiveKit/Vendor/GPUImage/iOS/Framework/GPUImageFramework.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageFramework.h rename to LFLiveKit/Vendor/GPUImage/iOS/Framework/GPUImageFramework.h diff --git a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageContext.h b/LFLiveKit/Vendor/GPUImage/iOS/GPUImageContext.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageContext.h rename to LFLiveKit/Vendor/GPUImage/iOS/GPUImageContext.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMovieWriter.h b/LFLiveKit/Vendor/GPUImage/iOS/GPUImageMovieWriter.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageMovieWriter.h rename to LFLiveKit/Vendor/GPUImage/iOS/GPUImageMovieWriter.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePicture+TextureSubimage.h b/LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture+TextureSubimage.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePicture+TextureSubimage.h rename to LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture+TextureSubimage.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePicture.h b/LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImagePicture.h rename to LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture.h 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/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageView.h b/LFLiveKit/Vendor/GPUImage/iOS/GPUImageView.h similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Headers/GPUImageView.h rename to LFLiveKit/Vendor/GPUImage/iOS/GPUImageView.h 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/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/amf.h b/LFLiveKit/Vendor/pili-librtmp/amf.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/amf.h rename to LFLiveKit/Vendor/pili-librtmp/amf.h diff --git a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/bytes.h b/LFLiveKit/Vendor/pili-librtmp/bytes.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/bytes.h rename to LFLiveKit/Vendor/pili-librtmp/bytes.h diff --git a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/dh.h b/LFLiveKit/Vendor/pili-librtmp/dh.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/dh.h rename to LFLiveKit/Vendor/pili-librtmp/dh.h diff --git a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/dhgroups.h b/LFLiveKit/Vendor/pili-librtmp/dhgroups.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/dhgroups.h rename to LFLiveKit/Vendor/pili-librtmp/dhgroups.h 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/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/error.h b/LFLiveKit/Vendor/pili-librtmp/error.h old mode 100755 new mode 100644 similarity index 96% rename from samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/error.h rename to LFLiveKit/Vendor/pili-librtmp/error.h index 6a8dcbe4..4ec31fda --- a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/error.h +++ b/LFLiveKit/Vendor/pili-librtmp/error.h @@ -10,7 +10,6 @@ typedef struct RTMPError { void RTMPError_Alloc(RTMPError *error, size_t msg_size); void RTMPError_Free(RTMPError *error); -void RTMPError_Message(RTMPError *error, int code, const char *message); // error defines enum { diff --git a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/handshake.h b/LFLiveKit/Vendor/pili-librtmp/handshake.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/handshake.h rename to LFLiveKit/Vendor/pili-librtmp/handshake.h 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/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/http.h b/LFLiveKit/Vendor/pili-librtmp/http.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/http.h rename to LFLiveKit/Vendor/pili-librtmp/http.h 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/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/log.h b/LFLiveKit/Vendor/pili-librtmp/log.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/log.h rename to LFLiveKit/Vendor/pili-librtmp/log.h 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/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/rtmp.h b/LFLiveKit/Vendor/pili-librtmp/rtmp.h old mode 100755 new mode 100644 similarity index 97% rename from samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/rtmp.h rename to LFLiveKit/Vendor/pili-librtmp/rtmp.h index d3879c01..d415e16c --- a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/rtmp.h +++ b/LFLiveKit/Vendor/pili-librtmp/rtmp.h @@ -50,7 +50,6 @@ extern "C" { #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_FEATURE_NONBLOCK 0x40 /* non block socket */ #define RTMP_PROTOCOL_UNDEFINED -1 #define RTMP_PROTOCOL_RTMP 0 @@ -103,7 +102,6 @@ typedef struct PILI_RTMPPacket { uint32_t m_nBytesRead; PILI_RTMPChunk *m_chunk; char *m_body; - int m_useExtTimestamp; } PILI_RTMPPacket; typedef struct PILI_RTMPSockBuf { @@ -335,7 +333,7 @@ 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 timeout); +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); @@ -347,14 +345,6 @@ 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); -#define MAJOR 1 -#define MINOR 0 -#define PATCH 4 - -int PILI_RTMP_Version(); - -const char * PILI_RTMP_GetReqId(); - /* hashswf.c */ int PILI_RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash, int age); diff --git a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/rtmp_sys.h b/LFLiveKit/Vendor/pili-librtmp/rtmp_sys.h old mode 100755 new mode 100644 similarity index 100% rename from samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Headers/rtmp_sys.h rename to LFLiveKit/Vendor/pili-librtmp/rtmp_sys.h diff --git a/LFLiveKit/filter/LFGPUImageBeautyFilter.h b/LFLiveKit/filter/LFGPUImageBeautyFilter.h index 1db560b4..03211585 100755 --- a/LFLiveKit/filter/LFGPUImageBeautyFilter.h +++ b/LFLiveKit/filter/LFGPUImageBeautyFilter.h @@ -1,4 +1,9 @@ +#if __has_include() +#import +#else #import "GPUImage.h" +#endif + @interface LFGPUImageBeautyFilter : GPUImageFilter { } diff --git a/LFLiveKit/filter/LFGPUImageEmptyFilter.h b/LFLiveKit/filter/LFGPUImageEmptyFilter.h index b5637c40..5aad12d6 100755 --- a/LFLiveKit/filter/LFGPUImageEmptyFilter.h +++ b/LFLiveKit/filter/LFGPUImageEmptyFilter.h @@ -1,4 +1,8 @@ +#if __has_include() +#import +#else #import "GPUImage.h" +#endif @interface LFGPUImageEmptyFilter : GPUImageFilter { diff --git a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo.xcodeproj/project.pbxproj b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo.xcodeproj/project.pbxproj index 69c5247b..71e18b7a 100644 --- a/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo.xcodeproj/project.pbxproj +++ b/samples/LFLiveKitFrameworkDemo/LFLiveKitFrameworkDemo.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ 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 */; }; @@ -14,9 +15,6 @@ 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 */; }; - 8495F6D31DB8F3CD00542124 /* LFLiveKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8495F6D01DB8F37E00542124 /* LFLiveKit.framework */; }; - 8495F6D71DB8F49800542124 /* GPUImage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8495F6D51DB8F49800542124 /* GPUImage.framework */; }; - 8495F6D81DB8F49800542124 /* pili-librtmp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8495F6D61DB8F49800542124 /* pili-librtmp.framework */; }; 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 */; }; @@ -38,6 +36,13 @@ /* 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 */; @@ -52,16 +57,10 @@ remoteGlobalIDString = 8495F66B1DB8F14600542124; remoteInfo = LFLiveKitFramework; }; - 8495F6D11DB8F3C400542124 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 8495F6C81DB8F37E00542124 /* LFLiveKit.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 8495F66A1DB8F14600542124; - 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 = ""; }; @@ -107,15 +106,13 @@ 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 */, - 8495F6D71DB8F49800542124 /* GPUImage.framework in Frameworks */, - 8495F6D81DB8F49800542124 /* pili-librtmp.framework in Frameworks */, - 8495F6D31DB8F3CD00542124 /* LFLiveKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -182,6 +179,7 @@ 8495F6D41DB8F49800542124 /* Frameworks */ = { isa = PBXGroup; children = ( + 843591671DD204FA00811FC7 /* libstdc++.6.0.9.tbd */, 84D003721DB8F8C200560583 /* Foundation.framework */, 84D003701DB8F8BD00560583 /* UIKit.framework */, 84D0036D1DB8F86D00560583 /* AVFoundation.framework */, @@ -237,7 +235,7 @@ buildRules = ( ); dependencies = ( - 8495F6D21DB8F3C400542124 /* PBXTargetDependency */, + 843591651DD201CC00811FC7 /* PBXTargetDependency */, ); name = LFLiveKitFrameworkDemo; productName = LFLiveKitFrameworkDemo; @@ -341,10 +339,10 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - 8495F6D21DB8F3C400542124 /* PBXTargetDependency */ = { + 843591651DD201CC00811FC7 /* PBXTargetDependency */ = { isa = PBXTargetDependency; name = LFLiveKitFramework; - targetProxy = 8495F6D11DB8F3C400542124 /* PBXContainerItemProxy */; + targetProxy = 843591641DD201CC00811FC7 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -408,7 +406,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -449,7 +447,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; @@ -461,14 +459,15 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEVELOPMENT_TEAM = G497YX6CBT; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/vendors", - ); - HEADER_SEARCH_PATHS = "\"$(SRCROOT)/vendors\""; + 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 = ""; + OTHER_LDFLAGS = ( + "$(inherited)", + "-ObjC", + ); PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKitFrameworkDemo; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -479,14 +478,15 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; DEVELOPMENT_TEAM = G497YX6CBT; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/vendors", - ); - HEADER_SEARCH_PATHS = "\"$(SRCROOT)/vendors\""; + 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 = ""; + OTHER_LDFLAGS = ( + "$(inherited)", + "-ObjC", + ); PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKitFrameworkDemo; PRODUCT_NAME = "$(TARGET_NAME)"; }; diff --git a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/GPUImage b/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/GPUImage deleted file mode 100644 index 6ecbe19d..00000000 Binary files a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/GPUImage and /dev/null differ diff --git a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Info.plist b/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Info.plist deleted file mode 100644 index f0d0b838..00000000 Binary files a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Info.plist and /dev/null differ diff --git a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Modules/module.modulemap b/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Modules/module.modulemap deleted file mode 100644 index 8b3de2aa..00000000 --- a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/Modules/module.modulemap +++ /dev/null @@ -1,6 +0,0 @@ -framework module GPUImage { - umbrella header "GPUImageFramework.h" - - export * - module * { export * } -} diff --git a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/_CodeSignature/CodeDirectory b/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/_CodeSignature/CodeDirectory deleted file mode 100644 index 8fc3b9e0..00000000 Binary files a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/_CodeSignature/CodeDirectory and /dev/null differ diff --git a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/_CodeSignature/CodeRequirements b/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/_CodeSignature/CodeRequirements deleted file mode 100644 index 05a7c129..00000000 Binary files a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/_CodeSignature/CodeRequirements and /dev/null differ diff --git a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/_CodeSignature/CodeRequirements-1 b/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/_CodeSignature/CodeRequirements-1 deleted file mode 100644 index 0f99cb74..00000000 Binary files a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/_CodeSignature/CodeRequirements-1 and /dev/null differ diff --git a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/_CodeSignature/CodeResources b/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/_CodeSignature/CodeResources deleted file mode 100644 index 751b8105..00000000 --- a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/_CodeSignature/CodeResources +++ /dev/null @@ -1,2706 +0,0 @@ - - - - - files - - Headers/GLProgram.h - - mxV0e3ySbX5wXHtFNuXmzouYzhg= - - Headers/GPUImage.h - - HUrEgiB6fAbHKKOhgpEMG/+gBtU= - - Headers/GPUImage3x3ConvolutionFilter.h - - 8dpkDAU1/CNJYbLCaopWMbtM9Wk= - - Headers/GPUImage3x3TextureSamplingFilter.h - - rmrLZgRfAct+MljSz+mZjuqx0Xc= - - Headers/GPUImageAdaptiveThresholdFilter.h - - j8TJ9SbuXJdDT6WeWbj67gedx0E= - - Headers/GPUImageAddBlendFilter.h - - ZqcgCRv7SDNUuNEWxmrvuwiJzs4= - - Headers/GPUImageAlphaBlendFilter.h - - 3+5qkq6u9LINJezWetcTsx/Hz4w= - - Headers/GPUImageAmatorkaFilter.h - - Jg2Vo6iBaPtVxTBtsPxFn2jUJvY= - - Headers/GPUImageAverageColor.h - - dm/LLHsaG/BYjGfGIJ+HVK85gjs= - - Headers/GPUImageAverageLuminanceThresholdFilter.h - - lfGX8xAQbjJzIZFxhCiFcAs7oy4= - - Headers/GPUImageBilateralFilter.h - - ZOYkrhlb8bo7XJYWCHKv8jDbGSw= - - Headers/GPUImageBoxBlurFilter.h - - 2IGx4AaFDNmXDeEMoT53K0JArEQ= - - Headers/GPUImageBrightnessFilter.h - - Ona6ET2F+oZePe4U8p1udhGII3Q= - - Headers/GPUImageBuffer.h - - JCpOP/4GQX0uEOQsJec2tEythNE= - - Headers/GPUImageBulgeDistortionFilter.h - - tLPJjW6QBH8Y8+nMB40CyTOjrIk= - - Headers/GPUImageCGAColorspaceFilter.h - - ZSc1+9LEc7ylEXYx6hfUlepSwbc= - - Headers/GPUImageCannyEdgeDetectionFilter.h - - RXd0CN9fZ1Mc2U4WEbfE5iLtv+A= - - Headers/GPUImageChromaKeyBlendFilter.h - - KE7yvI9BPOrZgZYWrjuxCZ8pVtA= - - Headers/GPUImageChromaKeyFilter.h - - NZEkB6hg/l9d0eeD8T5BIKeK/vA= - - Headers/GPUImageClosingFilter.h - - 8DaTIfa9mz8RZ8c7294Th71SvHE= - - Headers/GPUImageColorBlendFilter.h - - dMwymUIfKAFm83KD8q37++zNBWY= - - Headers/GPUImageColorBurnBlendFilter.h - - ZqWjCbNVUyVMyPHDsysdFsXHcd8= - - Headers/GPUImageColorConversion.h - - 85niOZxbuL7fm2tizONEMmbk5Go= - - Headers/GPUImageColorDodgeBlendFilter.h - - dyxixQU9GEwlWwohHx1TAxJJSCI= - - Headers/GPUImageColorInvertFilter.h - - BhDhrQlF0AE2zWv8hOsay7yd4P8= - - Headers/GPUImageColorLocalBinaryPatternFilter.h - - 9/Gb9ktJYdY40PRNmZK9G9kX0Qc= - - Headers/GPUImageColorMatrixFilter.h - - KRVW9ALkzhXgwAQQZ3WDkDENgr8= - - Headers/GPUImageColorPackingFilter.h - - WLiJEfbuwRZkJKU40m7s2pNU8z4= - - Headers/GPUImageColourFASTFeatureDetector.h - - GhE7L7L2F/nLxEjav9RYJLH+K1c= - - Headers/GPUImageColourFASTSamplingOperation.h - - /rRHQC73llgzJajpekh1DikWbVc= - - Headers/GPUImageContext.h - - crRuajGhAdPoHKDXPj2knPKAMQw= - - Headers/GPUImageContrastFilter.h - - yg9eIoi8mYMdPs664DRJY8fhCUE= - - Headers/GPUImageCropFilter.h - - GNsgNrng2NfpA6mZlL8mDRkO2Kk= - - Headers/GPUImageCrosshairGenerator.h - - XCPEj90Ghhdt475FjjXeQ17BWVE= - - Headers/GPUImageCrosshatchFilter.h - - X9+PdTNr6c59uDob6CaeLMBRh5w= - - Headers/GPUImageDarkenBlendFilter.h - - h2nCd0ZA9CpBgYaPiiCjWCXtjRQ= - - Headers/GPUImageDifferenceBlendFilter.h - - nQtt55uc8QDm8QAn4P3HCTlIsvA= - - Headers/GPUImageDilationFilter.h - - q1iT4ChRTeumN9ZpE6+lI+p82/E= - - Headers/GPUImageDirectionalNonMaximumSuppressionFilter.h - - YvyKHTi4RtM4TJCczJfI0VXbLpQ= - - Headers/GPUImageDirectionalSobelEdgeDetectionFilter.h - - c1sXRuGi690fcxh8OklQ07PGtJw= - - Headers/GPUImageDissolveBlendFilter.h - - 9F9Ov/HWqsMm5Xt1IssGPfrl2mc= - - Headers/GPUImageDivideBlendFilter.h - - RXn7OCQZLsvKTHiJbyHU79mrDKg= - - Headers/GPUImageEmbossFilter.h - - ihJeR7pFprPC2NrkgDGozQBoSKg= - - Headers/GPUImageErosionFilter.h - - kUdV57f6Lqf+cDNKhffApoWk71U= - - Headers/GPUImageExclusionBlendFilter.h - - 4gszly6+sRU6I+m8iNhlXab3Muw= - - Headers/GPUImageExposureFilter.h - - Pq0OBkMAQJfsz4c7axBaKguJuAM= - - Headers/GPUImageFASTCornerDetectionFilter.h - - y7bJW0+KUu7jyhck1iuVh/dMRSI= - - Headers/GPUImageFalseColorFilter.h - - FKHtRA6hwN4+v2+6syrGRpJs80s= - - Headers/GPUImageFilter.h - - RfmKJiQmvREjYI3efESP44q6HqY= - - Headers/GPUImageFilterGroup.h - - ci1P1K2/aqZPFXVlXh7s4sCxiDA= - - Headers/GPUImageFilterPipeline.h - - g8OwgwDaWscuTU8NSvFx3mW3Kyc= - - Headers/GPUImageFourInputFilter.h - - wi/A840uTQSq9r58rK6XxY2JrJQ= - - Headers/GPUImageFramebuffer.h - - IEeW8WJNFRGkd+ahOeP3W132M84= - - Headers/GPUImageFramebufferCache.h - - M1gALTDvDppaMmUPGKd9dcOy7ow= - - Headers/GPUImageFramework.h - - +epzM7KpjPip/rvReTzy3D1M8X8= - - Headers/GPUImageGammaFilter.h - - QXztmd+0AxvWQUgZGf/h/F5ogfA= - - Headers/GPUImageGaussianBlurFilter.h - - 7AyTt2ib3nefJBRgP9x0zMfaN7I= - - Headers/GPUImageGaussianBlurPositionFilter.h - - LPzQm8OikBgVvykqWgnGpCRjDeI= - - Headers/GPUImageGaussianSelectiveBlurFilter.h - - /JLdtp0oTNQDPqd78oh2Z6dRIQE= - - Headers/GPUImageGlassSphereFilter.h - - xNuoKVEKoDLca9saZMbO9t4O5nE= - - Headers/GPUImageGrayscaleFilter.h - - QyDCZY379dkN+s83dyiPuF1FTnE= - - Headers/GPUImageHSBFilter.h - - XAU4XGRlYmJJsdSYJv7DeCZyBaY= - - Headers/GPUImageHalftoneFilter.h - - Pr8rL4hd3Cy4Dk9j/sc+h1aDS4k= - - Headers/GPUImageHardLightBlendFilter.h - - jx/UK9UYuNtco7xUWs4u3jgihAs= - - Headers/GPUImageHarrisCornerDetectionFilter.h - - 2VBXLprDQkt75kNdsb2qiZMVBhI= - - Headers/GPUImageHazeFilter.h - - MKukhAyBDvtDmWfcqBB58cLUUtc= - - Headers/GPUImageHighPassFilter.h - - a6UTlsnfcqFwl7x5TmrswtX6TbQ= - - Headers/GPUImageHighlightShadowFilter.h - - RXF9rkKoFgO1yEf1lGYwnYVWaKA= - - Headers/GPUImageHistogramEqualizationFilter.h - - Jx3UmNICspUkpwl8TtCAJvOZlSM= - - Headers/GPUImageHistogramFilter.h - - +vKXk57tc2bLh6xg5saqO0gn0os= - - Headers/GPUImageHistogramGenerator.h - - pkT5KjxmW2JHBN0x1HaP4YPKIz8= - - Headers/GPUImageHoughTransformLineDetector.h - - wqP/sR0RJZhJw7q9kueAKfT4eIQ= - - Headers/GPUImageHueBlendFilter.h - - Gpv7ymmIGv+kMAvVjFn8/nzfGeo= - - Headers/GPUImageHueFilter.h - - KLyL+EyEdlFqtY6W60F0u++ky40= - - Headers/GPUImageJFAVoronoiFilter.h - - 3ui/efguz79qgvg0D6fqjAgh2Aw= - - Headers/GPUImageKuwaharaFilter.h - - fykYwSfuURCv41hLJGh5qBx057Q= - - Headers/GPUImageKuwaharaRadius3Filter.h - - nV+ZGOYZuJ3439z9GzV7yNfBHWg= - - Headers/GPUImageLanczosResamplingFilter.h - - +I/Oeo4QqenPG3rtjq44mj3ERB4= - - Headers/GPUImageLaplacianFilter.h - - RRZuKhYmTVGQDAcwMqlgQJbL8Do= - - Headers/GPUImageLevelsFilter.h - - Gza69S6pgnbnZlwHKqjYaYEM/Ls= - - Headers/GPUImageLightenBlendFilter.h - - hayBBt+FLU4U7NCnluqr5rS7xRk= - - Headers/GPUImageLineGenerator.h - - NQpyfhnEGd8NCcsAUYhjGqLSsv0= - - Headers/GPUImageLinearBurnBlendFilter.h - - MSZ5D8DfxhhcWSBE/dbyqIF1WXU= - - Headers/GPUImageLocalBinaryPatternFilter.h - - CoJvGvgmepvIE7xfBTmakrHwP/4= - - Headers/GPUImageLookupFilter.h - - w4z26ndizxXzKQJ88aVnAey4Fw0= - - Headers/GPUImageLowPassFilter.h - - 31VwJGSTw5Pk3rUIBteL3mS5Fco= - - Headers/GPUImageLuminanceRangeFilter.h - - 9bubuorseeL3CSW6/wDssVl51b0= - - Headers/GPUImageLuminanceThresholdFilter.h - - jriqFPHK7oD8U5a4NlRe5DAaCrE= - - Headers/GPUImageLuminosity.h - - D1xJBSH8RQe0r+tz433v5cooA4g= - - Headers/GPUImageLuminosityBlendFilter.h - - K9StpAOWlbVp000MEMTjrjPICtw= - - Headers/GPUImageMaskFilter.h - - 4me/bbKktSzR2tf91KFrCAFKpDw= - - Headers/GPUImageMedianFilter.h - - DCJ1QJxUxXII81YHvjbi2VxpGUY= - - Headers/GPUImageMissEtikateFilter.h - - eXaIKblZRY2u2zx4jbCECbbG5Vk= - - Headers/GPUImageMonochromeFilter.h - - w7+SR2N75c+NS0vIJnTpxjlcyCo= - - Headers/GPUImageMosaicFilter.h - - 4L1WsMRVAAen9AfkNC+gWJg+l5s= - - Headers/GPUImageMotionBlurFilter.h - - CxYZGDOwU5iVCUhz9pASd8U9E3k= - - Headers/GPUImageMotionDetector.h - - T38nrFQZbb4DT2gQK9w/CCUmglk= - - Headers/GPUImageMovie.h - - n79CDkhuW4T4K1DOrWsM+UlNvH4= - - Headers/GPUImageMovieComposition.h - - 9j3G+2oBkNiK1LmZya69OK7HPDw= - - Headers/GPUImageMovieWriter.h - - K/pCsJOeDezN4EvjevWNKuAoSBg= - - Headers/GPUImageMultiplyBlendFilter.h - - mKgyTRMmqRA8w9Xjc9C/f4ZwmAc= - - Headers/GPUImageNobleCornerDetectionFilter.h - - bv7MsymlAZaVPEyxgYOseUaQWBo= - - Headers/GPUImageNonMaximumSuppressionFilter.h - - RmDs6FthM8vOgj/yit6NluIJgVU= - - Headers/GPUImageNormalBlendFilter.h - - o+1YuPUIGNrBx31AftBi4v7uBsI= - - Headers/GPUImageOpacityFilter.h - - PWUf8xzWuDzIl6ozfDwkWo29bAY= - - Headers/GPUImageOpeningFilter.h - - f+ZpSToNCGDCmLBneSEM3GAGFkg= - - Headers/GPUImageOutput.h - - m3vHLviKj6yjen2H09FULLRYCCo= - - Headers/GPUImageOverlayBlendFilter.h - - 85PVdX0FilNUyQTKvAwCAs+CpgI= - - Headers/GPUImageParallelCoordinateLineTransformFilter.h - - pDJc3qAt8OZkni0KmcSGGZzeHdw= - - Headers/GPUImagePerlinNoiseFilter.h - - LEZfIm8tBunGxiLLQ2HpmDe2YFo= - - Headers/GPUImagePicture+TextureSubimage.h - - MTD+sWYHF3HDKTXOBU/4k+YtiPQ= - - Headers/GPUImagePicture.h - - YXNkWRwAyvK6BCCdUpyOohow230= - - Headers/GPUImagePinchDistortionFilter.h - - E5LEMQvCRVqxd6gsBT+AtZCkBUk= - - Headers/GPUImagePixellateFilter.h - - FHcv8OCM25q+A1skTZrcCx/Zu3Q= - - Headers/GPUImagePixellatePositionFilter.h - - Qz4V0yJTHDJTFP4omfEae9hrUmI= - - Headers/GPUImagePoissonBlendFilter.h - - lHLoDo44rTuaPiUPk4ND/XuE/qI= - - Headers/GPUImagePolarPixellateFilter.h - - 5aGVWSvzWEzu4viAYSY/9oiE3uI= - - Headers/GPUImagePolkaDotFilter.h - - SrpQ4VGsvj8g6sOzDJg/1KkQbgk= - - Headers/GPUImagePosterizeFilter.h - - cKYi3zjWrxNTAxMEKOr2dzuHkmc= - - Headers/GPUImagePrewittEdgeDetectionFilter.h - - N8toPrFwQ2Ugw+k+3OZuvSH/rM8= - - Headers/GPUImageRGBClosingFilter.h - - 0kDf1NDSmJa9qTXWXRJn0rqzVZM= - - Headers/GPUImageRGBDilationFilter.h - - ZR3Z5CpVv/S1H1a6U4H92d1XNuY= - - Headers/GPUImageRGBErosionFilter.h - - UGNRsq5EKscoJMw5AWmpNXYWTdM= - - Headers/GPUImageRGBFilter.h - - gkFaTAjOUwlssgYrnCqqNPqVZVQ= - - Headers/GPUImageRGBOpeningFilter.h - - a/PEfHNhIatpSnplj0x5m+Z/i0M= - - Headers/GPUImageRawDataInput.h - - bYPSXj/dY/MXY9pd631dd+SlD5Q= - - Headers/GPUImageRawDataOutput.h - - HI3YzUw4Cdi8JWb2rjQJQ/6EFew= - - Headers/GPUImageSaturationBlendFilter.h - - sVIc5ZOIrLTAYaM6iYDvrdQmllM= - - Headers/GPUImageSaturationFilter.h - - ArjLRNME7pbUYXWMMariBasSf2A= - - Headers/GPUImageScreenBlendFilter.h - - IlG+2VUkgjLPJPb6pjaf6qp8M7k= - - Headers/GPUImageSepiaFilter.h - - cersznQ+o5cekJw64xa6OobZLdw= - - Headers/GPUImageSharpenFilter.h - - V+QyaRQuTUpPftBbcZfmDw8wl64= - - Headers/GPUImageShiTomasiFeatureDetectionFilter.h - - pa7nhtULhfoyLOgoGvsm/+uhcfc= - - Headers/GPUImageSingleComponentGaussianBlurFilter.h - - 7/jSb9ceaMbbLIPMRzHvaXhXNXo= - - Headers/GPUImageSketchFilter.h - - kh4W2i34QVaPpUxLoB7QhmiZBMM= - - Headers/GPUImageSmoothToonFilter.h - - LBI7rJgJxalx0XL08kyxrw2i7dU= - - Headers/GPUImageSobelEdgeDetectionFilter.h - - rpWNWm5HHwlSq1ZQ1vaUiHShjhk= - - Headers/GPUImageSoftEleganceFilter.h - - NSpPLMjyIznNBnV+WlEbNU/JCrQ= - - Headers/GPUImageSoftLightBlendFilter.h - - LCmUXDPv2Y/1XTjM8l3xkfkTgjQ= - - Headers/GPUImageSolarizeFilter.h - - maBeg9l2rrPl76DuGl12ZFoyiro= - - Headers/GPUImageSolidColorGenerator.h - - obElPdknS4/M5NllFW4ou0UqW6k= - - Headers/GPUImageSourceOverBlendFilter.h - - dZ+4Jmo2+RTUBZ1ZwvOqklAUXNs= - - Headers/GPUImageSphereRefractionFilter.h - - /LGpL2OyUYK/pDU/r6rtolh+9HI= - - Headers/GPUImageStillCamera.h - - b1iHai/5pKKMH5szpPv1a8TqvHk= - - Headers/GPUImageStretchDistortionFilter.h - - dM2Pu4e4jVqbGEB/eTwojOVH/Oo= - - Headers/GPUImageSubtractBlendFilter.h - - 6eceNigAuB1MFFkkgb9wqH1cxts= - - Headers/GPUImageSwirlFilter.h - - W1EBsPkwgjRQ4g29xItEnYCj4m4= - - Headers/GPUImageTextureInput.h - - ZpUsaEiobJqk/ZWd2p34uo0Myk8= - - Headers/GPUImageTextureOutput.h - - FBr341QKXjYfCZRp9/tRKr7hPss= - - Headers/GPUImageThreeInputFilter.h - - O4NFo3F8qk6RKRe9vA4aN1nLcCo= - - Headers/GPUImageThresholdEdgeDetectionFilter.h - - 8XzR1Sd3L8iYTlhq4r1Iz+VQvOw= - - Headers/GPUImageThresholdSketchFilter.h - - qoUqrEAH1WyTko9oJYejdFlJ4vg= - - Headers/GPUImageThresholdedNonMaximumSuppressionFilter.h - - qlRa/0ARLN0BmYYIfBBscRL/laA= - - Headers/GPUImageTiltShiftFilter.h - - 2e6BVWefqZWB3q/boU0T3pywASk= - - Headers/GPUImageToneCurveFilter.h - - TUxmjstVUOFZkzUBdhC8py2pvlQ= - - Headers/GPUImageToonFilter.h - - IdFNHeEyRIrIFe7/BewlogHt6P8= - - Headers/GPUImageTransformFilter.h - - hYC1or0IxZQGx6tlTlsWGIEAGtg= - - Headers/GPUImageTwoInputCrossTextureSamplingFilter.h - - tTeOrYRvFnN+JRl1Zl1Pnx7WksM= - - Headers/GPUImageTwoInputFilter.h - - xYdAQuIcdQXjRF9BzTSZa6+epLY= - - Headers/GPUImageTwoPassFilter.h - - eIvODox9IFf/FwSDdwcO9QBlSuE= - - Headers/GPUImageTwoPassTextureSamplingFilter.h - - tJLxawc8sQqJNWN1mD+z/1HnW34= - - Headers/GPUImageUIElement.h - - gst311gU8Bppy9Y9ZJu1qsP15ig= - - Headers/GPUImageUnsharpMaskFilter.h - - tvbQ+h7cIOa1obTOfERZEKlMLgc= - - Headers/GPUImageVideoCamera.h - - ZJU1/2IWDnlHhL+SUU00uR55r1A= - - Headers/GPUImageView.h - - JttiO2LRvk7193e1j1cJBYNlqwc= - - Headers/GPUImageVignetteFilter.h - - 6/RMBS0wP+W+Qrdw9XbQFwR+A2U= - - Headers/GPUImageVoronoiConsumerFilter.h - - uRq8kWqFIpZtAzB8vM+lmf3/NqE= - - Headers/GPUImageWeakPixelInclusionFilter.h - - 7dtwUyahMxEVLznJA5pilE+TxIE= - - Headers/GPUImageWhiteBalanceFilter.h - - 0zBzM5GkMhSrWwtB//vJZzLVYDY= - - Headers/GPUImageXYDerivativeFilter.h - - s3VqLQtQvt8iRXqYCetH4F4V3/E= - - Headers/GPUImageZoomBlurFilter.h - - w0V2pYVUIFam3/3fhAX2qNtesCg= - - Headers/GPUImageiOSBlurFilter.h - - bq2sOdRJnN77Fv7I1e2CXZj/pFU= - - Info.plist - - w3jhhVVo7ss7Ny6+bhJfoPy0Zkg= - - Modules/module.modulemap - - R0/ACD1+K7JSlm2BJjfVTa4Z+LU= - - - files2 - - Headers/GLProgram.h - - hash - - mxV0e3ySbX5wXHtFNuXmzouYzhg= - - hash2 - - cFNmhWSDusMHEdqpJfIR7brb3prKF57vcZvlycZdoHI= - - - Headers/GPUImage.h - - hash - - HUrEgiB6fAbHKKOhgpEMG/+gBtU= - - hash2 - - gCGjyabgeFTu22qH526YkzarVuRd9yaX2OvJJ+Uev8E= - - - Headers/GPUImage3x3ConvolutionFilter.h - - hash - - 8dpkDAU1/CNJYbLCaopWMbtM9Wk= - - hash2 - - xW5JKVXtLwSIAOrNgUXYjc/T9F5+KEHtYly/uZYArp8= - - - Headers/GPUImage3x3TextureSamplingFilter.h - - hash - - rmrLZgRfAct+MljSz+mZjuqx0Xc= - - hash2 - - Me9DNBv+hsueQ9mH3bA/KkSdJbhip+b4FISjXoSHJlA= - - - Headers/GPUImageAdaptiveThresholdFilter.h - - hash - - j8TJ9SbuXJdDT6WeWbj67gedx0E= - - hash2 - - JCjHdq5EZY9TwTT1tO6Nrn0wWoNtN4QuwjM2LYKuzUs= - - - Headers/GPUImageAddBlendFilter.h - - hash - - ZqcgCRv7SDNUuNEWxmrvuwiJzs4= - - hash2 - - 7gmZKD4J/fSK0RH73+78MMXi2pGR/lX39LxhYuPIlkk= - - - Headers/GPUImageAlphaBlendFilter.h - - hash - - 3+5qkq6u9LINJezWetcTsx/Hz4w= - - hash2 - - bCTpScq9pex2+9XImOCbyBD/39vhUa+Cx6nlMoQqwNI= - - - Headers/GPUImageAmatorkaFilter.h - - hash - - Jg2Vo6iBaPtVxTBtsPxFn2jUJvY= - - hash2 - - 6Ou2XXACuqdDQD9WCPdBCcjkiH+60zgXW+s+gKKb7hA= - - - Headers/GPUImageAverageColor.h - - hash - - dm/LLHsaG/BYjGfGIJ+HVK85gjs= - - hash2 - - Pf20DWn4dVHN+h8pwCk3C92z9OgfdL7vGnXnIBY6LVM= - - - Headers/GPUImageAverageLuminanceThresholdFilter.h - - hash - - lfGX8xAQbjJzIZFxhCiFcAs7oy4= - - hash2 - - mdN2HqPP0Iy1htv3zhyvCc2JufGN0pzoU/qw3uTcs78= - - - Headers/GPUImageBilateralFilter.h - - hash - - ZOYkrhlb8bo7XJYWCHKv8jDbGSw= - - hash2 - - Nh6VMUmgAGF2QECzVLbt4EnbUSusVlDj9cz7GIid8oE= - - - Headers/GPUImageBoxBlurFilter.h - - hash - - 2IGx4AaFDNmXDeEMoT53K0JArEQ= - - hash2 - - LHpwW3ZUOsDNWkHX6KqdZCr/jSVkQcnK9lWRwHnOBxQ= - - - Headers/GPUImageBrightnessFilter.h - - hash - - Ona6ET2F+oZePe4U8p1udhGII3Q= - - hash2 - - uGqFvx3H/92XB/hy0e+pAbeYXXhGAhTpB2f1IEf0cpI= - - - Headers/GPUImageBuffer.h - - hash - - JCpOP/4GQX0uEOQsJec2tEythNE= - - hash2 - - yECIjMLc6eZvqNulDXpA3kaUruGk/heKH9aFvRsAZVA= - - - Headers/GPUImageBulgeDistortionFilter.h - - hash - - tLPJjW6QBH8Y8+nMB40CyTOjrIk= - - hash2 - - s/SegywwWdr1RgFqmEsPnRtWvhjBZNb1+yNzL8YgsEg= - - - Headers/GPUImageCGAColorspaceFilter.h - - hash - - ZSc1+9LEc7ylEXYx6hfUlepSwbc= - - hash2 - - /wXNLUCQLKq6PkKDK5WzjS2EfjjsQLYQFGQTZI+0xp8= - - - Headers/GPUImageCannyEdgeDetectionFilter.h - - hash - - RXd0CN9fZ1Mc2U4WEbfE5iLtv+A= - - hash2 - - tTJWe4zmN05lZmS4oOUx9CzBkknlq1xQebsvMK+FWfE= - - - Headers/GPUImageChromaKeyBlendFilter.h - - hash - - KE7yvI9BPOrZgZYWrjuxCZ8pVtA= - - hash2 - - geCwMVNljHatBw4YnXFM39Tgg7X1ql80uf3dQoZ8tSE= - - - Headers/GPUImageChromaKeyFilter.h - - hash - - NZEkB6hg/l9d0eeD8T5BIKeK/vA= - - hash2 - - LpBy1D6LazIVuHwutyP2+9sy/X1EudesfpEwL/A3f3M= - - - Headers/GPUImageClosingFilter.h - - hash - - 8DaTIfa9mz8RZ8c7294Th71SvHE= - - hash2 - - AKU1tHPVrLaDc9Om3PyocfDGl+9EfE+FkrlxwfGal6M= - - - Headers/GPUImageColorBlendFilter.h - - hash - - dMwymUIfKAFm83KD8q37++zNBWY= - - hash2 - - w+9krqv5lm0xceQzDfGv6SvE5xs7uQ5RlzfQAdd22EU= - - - Headers/GPUImageColorBurnBlendFilter.h - - hash - - ZqWjCbNVUyVMyPHDsysdFsXHcd8= - - hash2 - - tL4oNJsSrtqk0uuYJhz6F3vd3zb5I6yvXPbJDOUsn+A= - - - Headers/GPUImageColorConversion.h - - hash - - 85niOZxbuL7fm2tizONEMmbk5Go= - - hash2 - - 1eiW3wJuxOGdPQh7phrLdYIID/tXbV9HQoza42P9Sd8= - - - Headers/GPUImageColorDodgeBlendFilter.h - - hash - - dyxixQU9GEwlWwohHx1TAxJJSCI= - - hash2 - - 4DyV7HnuSnHa9ISHsFb9ssbUvfFaChCf5jyZ1tOsD/Q= - - - Headers/GPUImageColorInvertFilter.h - - hash - - BhDhrQlF0AE2zWv8hOsay7yd4P8= - - hash2 - - YzIi7FgNtWJvY7UadHf73R+UJGrIBYMUDsnEhXrALmg= - - - Headers/GPUImageColorLocalBinaryPatternFilter.h - - hash - - 9/Gb9ktJYdY40PRNmZK9G9kX0Qc= - - hash2 - - g12nU5fmJP26jKOflrDNLqy1D7mz0te3pV0t4hRQLLs= - - - Headers/GPUImageColorMatrixFilter.h - - hash - - KRVW9ALkzhXgwAQQZ3WDkDENgr8= - - hash2 - - aKcILwJL8gO1SrF/c2Va6w4btva79iDJbficZAGlvSQ= - - - Headers/GPUImageColorPackingFilter.h - - hash - - WLiJEfbuwRZkJKU40m7s2pNU8z4= - - hash2 - - JjNjSXZQDauyyyJgozL1X2j47VP9+PyplnrngANUZtc= - - - Headers/GPUImageColourFASTFeatureDetector.h - - hash - - GhE7L7L2F/nLxEjav9RYJLH+K1c= - - hash2 - - XMBOXATlzFJPD4KMuHOajY+wLHYmvMuRn1isVcsuV+0= - - - Headers/GPUImageColourFASTSamplingOperation.h - - hash - - /rRHQC73llgzJajpekh1DikWbVc= - - hash2 - - qlqgfFU/8J9oZakhbm5XGQyUJJcY5lI82b/jdRDoct0= - - - Headers/GPUImageContext.h - - hash - - crRuajGhAdPoHKDXPj2knPKAMQw= - - hash2 - - 5lhTPPG7u0ZF/HzISZlD6CDW5lOYJgNV96cFpybIz/4= - - - Headers/GPUImageContrastFilter.h - - hash - - yg9eIoi8mYMdPs664DRJY8fhCUE= - - hash2 - - 0R1BTRgbARY9QRcxVLfSDtpd3gaw4LuB+aiixCvk594= - - - Headers/GPUImageCropFilter.h - - hash - - GNsgNrng2NfpA6mZlL8mDRkO2Kk= - - hash2 - - kcGtgvGutsxitzptDWfaFTXBGAsXoDsd233MVZjcPrM= - - - Headers/GPUImageCrosshairGenerator.h - - hash - - XCPEj90Ghhdt475FjjXeQ17BWVE= - - hash2 - - gT23uANRS7CGGyQW2AOydCdcC5sn0TEMlnc2Kwx7FKg= - - - Headers/GPUImageCrosshatchFilter.h - - hash - - X9+PdTNr6c59uDob6CaeLMBRh5w= - - hash2 - - vjrwI6OkrAz4SafSmeRdbNKNlM7kSre6hNXZGtmZvyU= - - - Headers/GPUImageDarkenBlendFilter.h - - hash - - h2nCd0ZA9CpBgYaPiiCjWCXtjRQ= - - hash2 - - rmgMHzR/bDFTmL+v3NYIBDVdQiLxWJxifazlvhASvnk= - - - Headers/GPUImageDifferenceBlendFilter.h - - hash - - nQtt55uc8QDm8QAn4P3HCTlIsvA= - - hash2 - - nEqCeHYvdyuMkFu7YrCrXhXzV83fvTrPjyGKcLZfAkg= - - - Headers/GPUImageDilationFilter.h - - hash - - q1iT4ChRTeumN9ZpE6+lI+p82/E= - - hash2 - - QvhTeaaqUez5RfDJMS8vYpdepiHpSKIdg4kKywJewg4= - - - Headers/GPUImageDirectionalNonMaximumSuppressionFilter.h - - hash - - YvyKHTi4RtM4TJCczJfI0VXbLpQ= - - hash2 - - dCeafsRFlU7i9O1kaSmfyuRHj6F5YquWCBdiSq7WAt4= - - - Headers/GPUImageDirectionalSobelEdgeDetectionFilter.h - - hash - - c1sXRuGi690fcxh8OklQ07PGtJw= - - hash2 - - uPdVfsGl/X7FD2BGMS642EI7uG1oalencOFoC3ObP+g= - - - Headers/GPUImageDissolveBlendFilter.h - - hash - - 9F9Ov/HWqsMm5Xt1IssGPfrl2mc= - - hash2 - - MNLt4fDp6XW6DqRDI85xMY1R/cKWUtkYaZTZ4pQuvpI= - - - Headers/GPUImageDivideBlendFilter.h - - hash - - RXn7OCQZLsvKTHiJbyHU79mrDKg= - - hash2 - - eCt2yGUiNGSa4GgdpJc4TI+vTrzfRTpj2fm5x2z/jxk= - - - Headers/GPUImageEmbossFilter.h - - hash - - ihJeR7pFprPC2NrkgDGozQBoSKg= - - hash2 - - 3ZNWgV1K5avYl8YlY+CsJ8C3xNmJ3hhSGjg9d/jwNaw= - - - Headers/GPUImageErosionFilter.h - - hash - - kUdV57f6Lqf+cDNKhffApoWk71U= - - hash2 - - VN+FfhbJbATpqb/Zt36Q6I7Av1NlXPu8ixGtOww45bU= - - - Headers/GPUImageExclusionBlendFilter.h - - hash - - 4gszly6+sRU6I+m8iNhlXab3Muw= - - hash2 - - IIfleEt/GWWFwGvOXX6VNZUn3Rgl1FALo/JkTdEqo5A= - - - Headers/GPUImageExposureFilter.h - - hash - - Pq0OBkMAQJfsz4c7axBaKguJuAM= - - hash2 - - v+jxvlZLXa/megMUIqo1f6/tllfptDuH5bDPPeLEMZE= - - - Headers/GPUImageFASTCornerDetectionFilter.h - - hash - - y7bJW0+KUu7jyhck1iuVh/dMRSI= - - hash2 - - KwujAFPj/udiOqcNfT++Y2gj/dx6Ci+tZqwK5tRrF0Y= - - - Headers/GPUImageFalseColorFilter.h - - hash - - FKHtRA6hwN4+v2+6syrGRpJs80s= - - hash2 - - VXayiyCKId/QDh37LKNXJlIyo+A8BE5MSxqbISiNnCs= - - - Headers/GPUImageFilter.h - - hash - - RfmKJiQmvREjYI3efESP44q6HqY= - - hash2 - - NUHqU0nOp+NoUiS3HPIvn53NgAg2APxYxdcSRQ65x0M= - - - Headers/GPUImageFilterGroup.h - - hash - - ci1P1K2/aqZPFXVlXh7s4sCxiDA= - - hash2 - - BBet206JJrO7eVZdeqXGkNb5UYfRrpAuxsgf8yVKEW8= - - - Headers/GPUImageFilterPipeline.h - - hash - - g8OwgwDaWscuTU8NSvFx3mW3Kyc= - - hash2 - - 3VS3ydBqsnaNvP97vVq5t+f7V9iEPaPAY3tnwvXleVI= - - - Headers/GPUImageFourInputFilter.h - - hash - - wi/A840uTQSq9r58rK6XxY2JrJQ= - - hash2 - - 4K2xLfLw9Tiqe0cjNKRow0LFIXhwoHEv8KgkuRDm9JQ= - - - Headers/GPUImageFramebuffer.h - - hash - - IEeW8WJNFRGkd+ahOeP3W132M84= - - hash2 - - rILL0gnwCJdmxUK37k6p6pxsHtgxchCyvjaMs5Np8+o= - - - Headers/GPUImageFramebufferCache.h - - hash - - M1gALTDvDppaMmUPGKd9dcOy7ow= - - hash2 - - jZVzaFZNXSJra69NHUmnvNkM518xrWsdLgHdp4hiDEw= - - - Headers/GPUImageFramework.h - - hash - - +epzM7KpjPip/rvReTzy3D1M8X8= - - hash2 - - Hy7Qk9anT+/NGiw5Y8tMlFiEr0BREQnCdJ8P4jHCPFo= - - - Headers/GPUImageGammaFilter.h - - hash - - QXztmd+0AxvWQUgZGf/h/F5ogfA= - - hash2 - - d6yphF+YkjQyapKF4p0v1sehxDq9JdNJA9rdG6jwIRE= - - - Headers/GPUImageGaussianBlurFilter.h - - hash - - 7AyTt2ib3nefJBRgP9x0zMfaN7I= - - hash2 - - BfvGEIx+1dlAhgwIDHIlj1LxfmCnQMxOsX4xqfHmRLo= - - - Headers/GPUImageGaussianBlurPositionFilter.h - - hash - - LPzQm8OikBgVvykqWgnGpCRjDeI= - - hash2 - - HjHIlqBKW4z7oqciN28CigRuOEhzVdXI33UUKf+F9rM= - - - Headers/GPUImageGaussianSelectiveBlurFilter.h - - hash - - /JLdtp0oTNQDPqd78oh2Z6dRIQE= - - hash2 - - 5dvYm9rz3CrntpGwHQ9Vje5caa74MU4nxwp9vZlsoa8= - - - Headers/GPUImageGlassSphereFilter.h - - hash - - xNuoKVEKoDLca9saZMbO9t4O5nE= - - hash2 - - HLx07OX1tOjkv9AgOZ37yVaIYqSa5+1GeHmwm7JPnbk= - - - Headers/GPUImageGrayscaleFilter.h - - hash - - QyDCZY379dkN+s83dyiPuF1FTnE= - - hash2 - - cSF1cY/HMUoefh0hA89ESiTnQIRRDiDfXOuc3wRh9Qc= - - - Headers/GPUImageHSBFilter.h - - hash - - XAU4XGRlYmJJsdSYJv7DeCZyBaY= - - hash2 - - /QPQd9EBYsMD3Je+yMz3mwXN3mqoGpbIJgjyLDiJZgI= - - - Headers/GPUImageHalftoneFilter.h - - hash - - Pr8rL4hd3Cy4Dk9j/sc+h1aDS4k= - - hash2 - - 0rmSnGbEGIZCqfb7C41uZjOl4AH1okMgXitgsX7p+lY= - - - Headers/GPUImageHardLightBlendFilter.h - - hash - - jx/UK9UYuNtco7xUWs4u3jgihAs= - - hash2 - - k0z2X6+IzW8YoznhQuWaw6H5HLeJ81a+8lKBOK9zJdU= - - - Headers/GPUImageHarrisCornerDetectionFilter.h - - hash - - 2VBXLprDQkt75kNdsb2qiZMVBhI= - - hash2 - - +ndKqu6zsGSqdWNa2H98k/zAC2oYJ6nIipPi1hqM2yI= - - - Headers/GPUImageHazeFilter.h - - hash - - MKukhAyBDvtDmWfcqBB58cLUUtc= - - hash2 - - BtRO2EkDifu/sIz6DyA3UPMUD/qEVmPnLujzfTKcJQU= - - - Headers/GPUImageHighPassFilter.h - - hash - - a6UTlsnfcqFwl7x5TmrswtX6TbQ= - - hash2 - - o3gWBrT/dajIE/+vYmETUSxpjfADVsfbz7y8j2a+YdA= - - - Headers/GPUImageHighlightShadowFilter.h - - hash - - RXF9rkKoFgO1yEf1lGYwnYVWaKA= - - hash2 - - 4w2o4nmX6zOpST3S8mU8dK4iZJwQkNcZhr53zaIltK0= - - - Headers/GPUImageHistogramEqualizationFilter.h - - hash - - Jx3UmNICspUkpwl8TtCAJvOZlSM= - - hash2 - - VoJJwsDkAfvkWyOaqu0SJHsS3aDLHDA1rVnzuFM/vHU= - - - Headers/GPUImageHistogramFilter.h - - hash - - +vKXk57tc2bLh6xg5saqO0gn0os= - - hash2 - - lrTjAFYyDOUJbykNnEGVSbRI/lQ9uqdYkiPhkyVuugI= - - - Headers/GPUImageHistogramGenerator.h - - hash - - pkT5KjxmW2JHBN0x1HaP4YPKIz8= - - hash2 - - TH+SyM7VDsjCvWytqun/L+RNMb/yW4w46qAfQJdC9mc= - - - Headers/GPUImageHoughTransformLineDetector.h - - hash - - wqP/sR0RJZhJw7q9kueAKfT4eIQ= - - hash2 - - pPG/kQV3hj+bIftMmZjMZBoD29du0Q8iCiurodqgGDk= - - - Headers/GPUImageHueBlendFilter.h - - hash - - Gpv7ymmIGv+kMAvVjFn8/nzfGeo= - - hash2 - - kl8ox+bvHqgvOUyFz2QetP0TJHHYVe8XEXPWDa6QqXY= - - - Headers/GPUImageHueFilter.h - - hash - - KLyL+EyEdlFqtY6W60F0u++ky40= - - hash2 - - y0o6JOPH/m/bB9uNlglh1MevHb6WH6es9hkaHIL32y0= - - - Headers/GPUImageJFAVoronoiFilter.h - - hash - - 3ui/efguz79qgvg0D6fqjAgh2Aw= - - hash2 - - 2JBWIFLqAomN1KrRTWPmQIDiiJe+3FO+t++0+WGxFfs= - - - Headers/GPUImageKuwaharaFilter.h - - hash - - fykYwSfuURCv41hLJGh5qBx057Q= - - hash2 - - sA9k/oTgFK0Uh9Dwrm9QMzvWmkpAT0IzN55j46IA4kI= - - - Headers/GPUImageKuwaharaRadius3Filter.h - - hash - - nV+ZGOYZuJ3439z9GzV7yNfBHWg= - - hash2 - - BXRlHK84VKTiMfwvlN/9sPsMrs54z4nngEh3dEVnT/Y= - - - Headers/GPUImageLanczosResamplingFilter.h - - hash - - +I/Oeo4QqenPG3rtjq44mj3ERB4= - - hash2 - - nQo96CIDe70PPP87+55eqs6vsXAVYG6Rs6kesPKSHFM= - - - Headers/GPUImageLaplacianFilter.h - - hash - - RRZuKhYmTVGQDAcwMqlgQJbL8Do= - - hash2 - - AF5wFEcKGWxvjjaveKJL4VaaIDbmSCIqtnmidc+aGLw= - - - Headers/GPUImageLevelsFilter.h - - hash - - Gza69S6pgnbnZlwHKqjYaYEM/Ls= - - hash2 - - aXA3DT9RZIr1T8Lb0MCEZtLkiHvmIZg+CBoO6J6NzLY= - - - Headers/GPUImageLightenBlendFilter.h - - hash - - hayBBt+FLU4U7NCnluqr5rS7xRk= - - hash2 - - ET8UyfBJmI72Y0s5rM8klqi/Jj+k8wrgia73aZEmOKE= - - - Headers/GPUImageLineGenerator.h - - hash - - NQpyfhnEGd8NCcsAUYhjGqLSsv0= - - hash2 - - MRGJih9v1PrQu3DCpQahMSa9E/GXpIXk10vMwJfqY24= - - - Headers/GPUImageLinearBurnBlendFilter.h - - hash - - MSZ5D8DfxhhcWSBE/dbyqIF1WXU= - - hash2 - - dIOIlj7F3HMneuRTcj5d9sNyw0qwwN0gS0jLl3PD/Ro= - - - Headers/GPUImageLocalBinaryPatternFilter.h - - hash - - CoJvGvgmepvIE7xfBTmakrHwP/4= - - hash2 - - R0t/ozlZz3TZNGjRJpNzuKLF7bax6SJwHhw8J5sYSXU= - - - Headers/GPUImageLookupFilter.h - - hash - - w4z26ndizxXzKQJ88aVnAey4Fw0= - - hash2 - - E3Qynm/Y9oW7yvkOxIzcFvGI5vO8e8BTUysXDxuB468= - - - Headers/GPUImageLowPassFilter.h - - hash - - 31VwJGSTw5Pk3rUIBteL3mS5Fco= - - hash2 - - JRwsk35Z93O3p1peS2R7IhojSxfaZ2BxY/TSK236zcg= - - - Headers/GPUImageLuminanceRangeFilter.h - - hash - - 9bubuorseeL3CSW6/wDssVl51b0= - - hash2 - - /NchnrcZU2Ddo9+BtBg71GduPyrLT9To5nlH7E4v7dA= - - - Headers/GPUImageLuminanceThresholdFilter.h - - hash - - jriqFPHK7oD8U5a4NlRe5DAaCrE= - - hash2 - - aCceuVzAuSv+gOY8IpiNBS4vKYcncCjY1iW16gtj2bA= - - - Headers/GPUImageLuminosity.h - - hash - - D1xJBSH8RQe0r+tz433v5cooA4g= - - hash2 - - UZ6egL2OTEHOYc7SbGFL5mFB89UIMBS6mnepqLs/B68= - - - Headers/GPUImageLuminosityBlendFilter.h - - hash - - K9StpAOWlbVp000MEMTjrjPICtw= - - hash2 - - gY3eod3igaQlf72xEVrKGHfgy3JhIYMdHtuB3OXhDkw= - - - Headers/GPUImageMaskFilter.h - - hash - - 4me/bbKktSzR2tf91KFrCAFKpDw= - - hash2 - - 44fLCgJZ3nhCD3I7K7dXE3LD8R1B+4HUcpLAZqxrb5k= - - - Headers/GPUImageMedianFilter.h - - hash - - DCJ1QJxUxXII81YHvjbi2VxpGUY= - - hash2 - - JgHNxoUacL1AoxlIyZmiBnOquVjx9E2dRNNF0Lnl9ZU= - - - Headers/GPUImageMissEtikateFilter.h - - hash - - eXaIKblZRY2u2zx4jbCECbbG5Vk= - - hash2 - - LN9dNAxJG2g52O8M5SXg1afyFd4sQLoR9NC2pv1SYqQ= - - - Headers/GPUImageMonochromeFilter.h - - hash - - w7+SR2N75c+NS0vIJnTpxjlcyCo= - - hash2 - - uu8UF8NzH4i5tzau8UgDGqBvvhfgQoJf7w2B/LQKdsQ= - - - Headers/GPUImageMosaicFilter.h - - hash - - 4L1WsMRVAAen9AfkNC+gWJg+l5s= - - hash2 - - vpR3pcz7VW5jYrsmx1tIfg79EG31heIYqzwKeSAxM1M= - - - Headers/GPUImageMotionBlurFilter.h - - hash - - CxYZGDOwU5iVCUhz9pASd8U9E3k= - - hash2 - - kP+MzWFY5m1pGKfRWkFtEk5OfcxJVeXsCwObUknkp6E= - - - Headers/GPUImageMotionDetector.h - - hash - - T38nrFQZbb4DT2gQK9w/CCUmglk= - - hash2 - - XeBbcomtRo0PFMPiJnYn8h+2BCGhE1sGab6QYnDqAio= - - - Headers/GPUImageMovie.h - - hash - - n79CDkhuW4T4K1DOrWsM+UlNvH4= - - hash2 - - J9fI4lSsBinopjsPyjcN2QjqT7oZUmMzsL7A/vxh0DE= - - - Headers/GPUImageMovieComposition.h - - hash - - 9j3G+2oBkNiK1LmZya69OK7HPDw= - - hash2 - - aaw9hmnu18hWgAIEZZ9MxM3EVW02tzTcE4d18AZbigI= - - - Headers/GPUImageMovieWriter.h - - hash - - K/pCsJOeDezN4EvjevWNKuAoSBg= - - hash2 - - Oc4EIGiCqCU9k52XDAonto6br6IQsE0dNiacgjD6yew= - - - Headers/GPUImageMultiplyBlendFilter.h - - hash - - mKgyTRMmqRA8w9Xjc9C/f4ZwmAc= - - hash2 - - 9VW9vhsoZhmlS5i+ZTPdztkJz1vHh0+7KiComOfMSSE= - - - Headers/GPUImageNobleCornerDetectionFilter.h - - hash - - bv7MsymlAZaVPEyxgYOseUaQWBo= - - hash2 - - AMu9H7HP3AMOA6XRPwGWJOFEmaOu8bDY6ENZTn4S4Lk= - - - Headers/GPUImageNonMaximumSuppressionFilter.h - - hash - - RmDs6FthM8vOgj/yit6NluIJgVU= - - hash2 - - MOpciC/fDhr5mzbhVwjdtqfJjB8050Lc7fxLCqTOaoo= - - - Headers/GPUImageNormalBlendFilter.h - - hash - - o+1YuPUIGNrBx31AftBi4v7uBsI= - - hash2 - - KWYr1P82qvyRov0sPsAt7wgrEPS66a0CS2VX/l9O2mU= - - - Headers/GPUImageOpacityFilter.h - - hash - - PWUf8xzWuDzIl6ozfDwkWo29bAY= - - hash2 - - YU2SITgJxfijq4dMwA1rn+ap7ofJ4GZApfBODdnWz6k= - - - Headers/GPUImageOpeningFilter.h - - hash - - f+ZpSToNCGDCmLBneSEM3GAGFkg= - - hash2 - - iupkkLTpcTlVCCHR/Z+AjzpWBD0hiZ3OL0MUyGI3dts= - - - Headers/GPUImageOutput.h - - hash - - m3vHLviKj6yjen2H09FULLRYCCo= - - hash2 - - eNV7T+Ps5995UCwfqui5bOWl4jfSdJGrdfIAuj84Rvk= - - - Headers/GPUImageOverlayBlendFilter.h - - hash - - 85PVdX0FilNUyQTKvAwCAs+CpgI= - - hash2 - - 8jf5Nau0HK2mRHlKn2bsZ4tpnqUpaAxE+jTcDAuLbRo= - - - Headers/GPUImageParallelCoordinateLineTransformFilter.h - - hash - - pDJc3qAt8OZkni0KmcSGGZzeHdw= - - hash2 - - z/fymwIbzghrhsMaUBiU7mpMVgBOJEZ/+mg6edKFbOg= - - - Headers/GPUImagePerlinNoiseFilter.h - - hash - - LEZfIm8tBunGxiLLQ2HpmDe2YFo= - - hash2 - - SQdXvQUqxGOC4T1eQioh3t92KeSssTu4dCc0OJbKVas= - - - Headers/GPUImagePicture+TextureSubimage.h - - hash - - MTD+sWYHF3HDKTXOBU/4k+YtiPQ= - - hash2 - - 5ZfRJAF6cru81m3JCVLq64ZBuCS44FLHA6dK4jZacYc= - - - Headers/GPUImagePicture.h - - hash - - YXNkWRwAyvK6BCCdUpyOohow230= - - hash2 - - S7E95qShrP+xcVb0AoVzHEvOhXej5NBk3is3iciYdk8= - - - Headers/GPUImagePinchDistortionFilter.h - - hash - - E5LEMQvCRVqxd6gsBT+AtZCkBUk= - - hash2 - - hKVURpakr3W8xaLY6RniEcb4RtnaM2lqZ3kvUGX81ic= - - - Headers/GPUImagePixellateFilter.h - - hash - - FHcv8OCM25q+A1skTZrcCx/Zu3Q= - - hash2 - - zg1aFxBRXQuzEXKYLhw6AIoOPagEXlkQcmDsBvbZ6bE= - - - Headers/GPUImagePixellatePositionFilter.h - - hash - - Qz4V0yJTHDJTFP4omfEae9hrUmI= - - hash2 - - ZyjKNlPPzw2jpVYF2N6aSTwWVBAf493YJvwaJEE3mgU= - - - Headers/GPUImagePoissonBlendFilter.h - - hash - - lHLoDo44rTuaPiUPk4ND/XuE/qI= - - hash2 - - DIu/PL3Z/lwkNnrm/eb9Zr3CHUIbNOd1joQVqSRoj4E= - - - Headers/GPUImagePolarPixellateFilter.h - - hash - - 5aGVWSvzWEzu4viAYSY/9oiE3uI= - - hash2 - - V2t+bRltNSBKaGn4RiSK3i6rzfXQDN5sEGXlQLBCVvs= - - - Headers/GPUImagePolkaDotFilter.h - - hash - - SrpQ4VGsvj8g6sOzDJg/1KkQbgk= - - hash2 - - cOe85ACBynlEg6fXjt3/UWUDN0THJCa7xNPQdRRJZzg= - - - Headers/GPUImagePosterizeFilter.h - - hash - - cKYi3zjWrxNTAxMEKOr2dzuHkmc= - - hash2 - - lw0hmuQnnzI/WHe0bkUJRJbR6ywZKAK0rBNgceNhQ4o= - - - Headers/GPUImagePrewittEdgeDetectionFilter.h - - hash - - N8toPrFwQ2Ugw+k+3OZuvSH/rM8= - - hash2 - - GgmG5NLg6kFpZARGa9HrYAWjTJ8rAVojkF2BGCZ8l6w= - - - Headers/GPUImageRGBClosingFilter.h - - hash - - 0kDf1NDSmJa9qTXWXRJn0rqzVZM= - - hash2 - - c0+MFJk161JMv3y3sze/mDS2hDNRDRBe+z7mI1nyJGA= - - - Headers/GPUImageRGBDilationFilter.h - - hash - - ZR3Z5CpVv/S1H1a6U4H92d1XNuY= - - hash2 - - iGqoh0JYt8UbB3Lt8xW39hKGIqXE2q5FQKn6jhYbfsk= - - - Headers/GPUImageRGBErosionFilter.h - - hash - - UGNRsq5EKscoJMw5AWmpNXYWTdM= - - hash2 - - fsgqB8hh8oihlpdu33ab0FKwexgQhHhB6wZ/pXHM7j8= - - - Headers/GPUImageRGBFilter.h - - hash - - gkFaTAjOUwlssgYrnCqqNPqVZVQ= - - hash2 - - JwGWLCiHtrpt8JoE/FPaguX+O/UnPMEyhq2TQ+g8J/0= - - - Headers/GPUImageRGBOpeningFilter.h - - hash - - a/PEfHNhIatpSnplj0x5m+Z/i0M= - - hash2 - - wPibkpF3L/UUegJv1oHN7YzItjd1POfuS32ti6ZFUE8= - - - Headers/GPUImageRawDataInput.h - - hash - - bYPSXj/dY/MXY9pd631dd+SlD5Q= - - hash2 - - zzOxphZH2h5xHQG/SkKtkp9sbn9E4NGwZTdpP+VQr70= - - - Headers/GPUImageRawDataOutput.h - - hash - - HI3YzUw4Cdi8JWb2rjQJQ/6EFew= - - hash2 - - Wdvq2164pOjm+QdkxG3JRdwbOP1AViTbcDaDts4m+OU= - - - Headers/GPUImageSaturationBlendFilter.h - - hash - - sVIc5ZOIrLTAYaM6iYDvrdQmllM= - - hash2 - - j5Xw76lCYYHHF0OCr5buwU5buMO721YBeFBC4LTDfd8= - - - Headers/GPUImageSaturationFilter.h - - hash - - ArjLRNME7pbUYXWMMariBasSf2A= - - hash2 - - kTfjt6W8zKzvySulYNsAi2GO5FIqcalE8T2q9Osm+SA= - - - Headers/GPUImageScreenBlendFilter.h - - hash - - IlG+2VUkgjLPJPb6pjaf6qp8M7k= - - hash2 - - zRoyxXOR4v+JabDEN8AScZH9i7NHO9EXGh3dg4iVF0c= - - - Headers/GPUImageSepiaFilter.h - - hash - - cersznQ+o5cekJw64xa6OobZLdw= - - hash2 - - EOFwAQk6nmGdliRc3qoILx10b2LVlWnuJRGDmt+Mo+s= - - - Headers/GPUImageSharpenFilter.h - - hash - - V+QyaRQuTUpPftBbcZfmDw8wl64= - - hash2 - - MWQp5QmDIl7folDxjAjYqzY4ExDcYNxXDQ5BT2Zf5Fg= - - - Headers/GPUImageShiTomasiFeatureDetectionFilter.h - - hash - - pa7nhtULhfoyLOgoGvsm/+uhcfc= - - hash2 - - hckgWZWzeoGiwik1hozEhEZV0oyDDd/L5lJADeqJUUw= - - - Headers/GPUImageSingleComponentGaussianBlurFilter.h - - hash - - 7/jSb9ceaMbbLIPMRzHvaXhXNXo= - - hash2 - - yjGn49aEMOyI+uL9JLS6k+5jy3jFjYXkvMiF0+OrqiQ= - - - Headers/GPUImageSketchFilter.h - - hash - - kh4W2i34QVaPpUxLoB7QhmiZBMM= - - hash2 - - 9bX46choNKf3/pNqSfKi0ZRjVp3fwoE+FOraWoXT5U8= - - - Headers/GPUImageSmoothToonFilter.h - - hash - - LBI7rJgJxalx0XL08kyxrw2i7dU= - - hash2 - - n3c9Dpr6M6F5vnRxsRRM/Xs/pSCHdeW8agCaw/VhdtM= - - - Headers/GPUImageSobelEdgeDetectionFilter.h - - hash - - rpWNWm5HHwlSq1ZQ1vaUiHShjhk= - - hash2 - - vUe/xIvG0/XHntNgdHn/UZJ1UIrEGV3LpwC/5WyP8FY= - - - Headers/GPUImageSoftEleganceFilter.h - - hash - - NSpPLMjyIznNBnV+WlEbNU/JCrQ= - - hash2 - - rRxPvkX+g8XECQXRtpzE4LDHM05y38HkJtm8v+IQpbw= - - - Headers/GPUImageSoftLightBlendFilter.h - - hash - - LCmUXDPv2Y/1XTjM8l3xkfkTgjQ= - - hash2 - - zx5jAItoAxN4cpOM7q/5bGu+3KZkWHG9YCPm+3qm/Do= - - - Headers/GPUImageSolarizeFilter.h - - hash - - maBeg9l2rrPl76DuGl12ZFoyiro= - - hash2 - - X/gAHJd5EBZWZ5EpyJOq3SAOCpmfJn+V0ygY7DedRuo= - - - Headers/GPUImageSolidColorGenerator.h - - hash - - obElPdknS4/M5NllFW4ou0UqW6k= - - hash2 - - N4bXTgVq0M+q6ebq+5jIKzZHNoIRnI8m4hK+yc+hZBI= - - - Headers/GPUImageSourceOverBlendFilter.h - - hash - - dZ+4Jmo2+RTUBZ1ZwvOqklAUXNs= - - hash2 - - L6DvPi/MXUnI57bPnCK7yJhWRbcz+UTssUeKoFRi7wQ= - - - Headers/GPUImageSphereRefractionFilter.h - - hash - - /LGpL2OyUYK/pDU/r6rtolh+9HI= - - hash2 - - IKSKm4l8karsOC8//09n3U4n0/D4MWY/9hZd7ucXYTE= - - - Headers/GPUImageStillCamera.h - - hash - - b1iHai/5pKKMH5szpPv1a8TqvHk= - - hash2 - - O8/dgEjSaZqkBxS9d/Cu8O9TfON8T5YLSMpAl0lpjHY= - - - Headers/GPUImageStretchDistortionFilter.h - - hash - - dM2Pu4e4jVqbGEB/eTwojOVH/Oo= - - hash2 - - N+Food7xczbywFGgKdlBT0YerM9AdnHwDXTbJXxINGQ= - - - Headers/GPUImageSubtractBlendFilter.h - - hash - - 6eceNigAuB1MFFkkgb9wqH1cxts= - - hash2 - - q6PvLPwaNqoHWXR2qFBIBzuX5CtbGH5QCJq/lyC3tug= - - - Headers/GPUImageSwirlFilter.h - - hash - - W1EBsPkwgjRQ4g29xItEnYCj4m4= - - hash2 - - gJbbUid87G8hYGaiJzjcdUKCg51Ml9P4WvOVQIFxXH8= - - - Headers/GPUImageTextureInput.h - - hash - - ZpUsaEiobJqk/ZWd2p34uo0Myk8= - - hash2 - - PpUr8cpxdLNEx0EmKVjGH+LFkPgbwR+hZYhJAaFqMS4= - - - Headers/GPUImageTextureOutput.h - - hash - - FBr341QKXjYfCZRp9/tRKr7hPss= - - hash2 - - B9+caOoMwnej6JBzj6LYBeCEERU9aEuc1WKXzVHukY8= - - - Headers/GPUImageThreeInputFilter.h - - hash - - O4NFo3F8qk6RKRe9vA4aN1nLcCo= - - hash2 - - SOfrv/URsFozR9VcwGsqbbKPKnXUZ1QUXMkksdGTCjs= - - - Headers/GPUImageThresholdEdgeDetectionFilter.h - - hash - - 8XzR1Sd3L8iYTlhq4r1Iz+VQvOw= - - hash2 - - Qa8DBG/NW9e/RUwZNhIeUkU14CXlD/lczigMJUrienY= - - - Headers/GPUImageThresholdSketchFilter.h - - hash - - qoUqrEAH1WyTko9oJYejdFlJ4vg= - - hash2 - - 30KG9/JXFlgwAPZfb45q8G1U9k5TQASuJ0fqa2MA3Dk= - - - Headers/GPUImageThresholdedNonMaximumSuppressionFilter.h - - hash - - qlRa/0ARLN0BmYYIfBBscRL/laA= - - hash2 - - ZBR5uOGseMKjNnCQHgtsMAdVnk6ur2SsxZkr2V21VMo= - - - Headers/GPUImageTiltShiftFilter.h - - hash - - 2e6BVWefqZWB3q/boU0T3pywASk= - - hash2 - - 5riLyAkS5NqMszJpHMYIp3nKke/8DbLH1iPSQILEDPs= - - - Headers/GPUImageToneCurveFilter.h - - hash - - TUxmjstVUOFZkzUBdhC8py2pvlQ= - - hash2 - - N9zDY7hAy5HZMyYbdca2Iue0igCNIpRhzKESgj9Ea9I= - - - Headers/GPUImageToonFilter.h - - hash - - IdFNHeEyRIrIFe7/BewlogHt6P8= - - hash2 - - cOTltWGPEhT/cO+57ACQlz1kN4YRzTF+9PYxnRuij8M= - - - Headers/GPUImageTransformFilter.h - - hash - - hYC1or0IxZQGx6tlTlsWGIEAGtg= - - hash2 - - uTs9cKEsBvpuOCy3AKTaQ/yW0+AOcQOOGFxhVJICyfU= - - - Headers/GPUImageTwoInputCrossTextureSamplingFilter.h - - hash - - tTeOrYRvFnN+JRl1Zl1Pnx7WksM= - - hash2 - - DHHFuOrA6opK/k2Xf6TqWvaeCNqypU4ni+Xtp4aSfaw= - - - Headers/GPUImageTwoInputFilter.h - - hash - - xYdAQuIcdQXjRF9BzTSZa6+epLY= - - hash2 - - wTMtDJ7dagkp3XU4G5GMzKDEw7nd4IFKTSrhpiI9ixk= - - - Headers/GPUImageTwoPassFilter.h - - hash - - eIvODox9IFf/FwSDdwcO9QBlSuE= - - hash2 - - SagpZ7zCovvMLtAZO5NgpY8Uau+JaMrAvdCv9L4ikm4= - - - Headers/GPUImageTwoPassTextureSamplingFilter.h - - hash - - tJLxawc8sQqJNWN1mD+z/1HnW34= - - hash2 - - 1ZXpcyRsASuwbTJv9gUkW5kOzjOm7BSeHLCGSnVX20Q= - - - Headers/GPUImageUIElement.h - - hash - - gst311gU8Bppy9Y9ZJu1qsP15ig= - - hash2 - - yaQMsskSlJGUlmmsWQIlemOdJr8w2x544SvX3K4X3OE= - - - Headers/GPUImageUnsharpMaskFilter.h - - hash - - tvbQ+h7cIOa1obTOfERZEKlMLgc= - - hash2 - - hjJzJqo1V3NzioKoh8RUxrv7ocAuPWwt42fJn9P+pxs= - - - Headers/GPUImageVideoCamera.h - - hash - - ZJU1/2IWDnlHhL+SUU00uR55r1A= - - hash2 - - IK85izbvkukB3otOJPCfbzu4xT89NMju/fLvmXHT2HA= - - - Headers/GPUImageView.h - - hash - - JttiO2LRvk7193e1j1cJBYNlqwc= - - hash2 - - uzK5RM09dP1YQyShaelRxyx96hsXq7+nuFe3RiMTOGQ= - - - Headers/GPUImageVignetteFilter.h - - hash - - 6/RMBS0wP+W+Qrdw9XbQFwR+A2U= - - hash2 - - KUx+kPEOujDg1vEHKNxCJ/IpKNQqqCcgbFwhzkfYZ/o= - - - Headers/GPUImageVoronoiConsumerFilter.h - - hash - - uRq8kWqFIpZtAzB8vM+lmf3/NqE= - - hash2 - - Wkb3AFqrlTm2PlWiJmV/l2fmzwUfqHHNNwBgYwkT08Q= - - - Headers/GPUImageWeakPixelInclusionFilter.h - - hash - - 7dtwUyahMxEVLznJA5pilE+TxIE= - - hash2 - - jeUFEwTVEJIJ+vvpp1F4D9WcxtGDRopCuyIFOVjZNNg= - - - Headers/GPUImageWhiteBalanceFilter.h - - hash - - 0zBzM5GkMhSrWwtB//vJZzLVYDY= - - hash2 - - 6+iCbOlWI+6MQRp1hkJP3UAp//Zy2lAkhCVOa8B0cdM= - - - Headers/GPUImageXYDerivativeFilter.h - - hash - - s3VqLQtQvt8iRXqYCetH4F4V3/E= - - hash2 - - 42JierB3Feua24ZX4cPf4ntsfK2QPveQlVJ5L1tmX7o= - - - Headers/GPUImageZoomBlurFilter.h - - hash - - w0V2pYVUIFam3/3fhAX2qNtesCg= - - hash2 - - v4JMN9d0pq+IQA7BT48+iOMT5UTyQ1OQ/aa63dBW5s0= - - - Headers/GPUImageiOSBlurFilter.h - - hash - - bq2sOdRJnN77Fv7I1e2CXZj/pFU= - - hash2 - - ZIpPOgWu86QLBgDlCCnH6BFoTKNxHbGuNIblBFuoJ3c= - - - Modules/module.modulemap - - hash - - R0/ACD1+K7JSlm2BJjfVTa4Z+LU= - - hash2 - - 2s78k1ou/hrQ+/btMmSKO1GX/hH0oV4uaGcScKVpFyA= - - - - rules - - ^ - - ^.*\.lproj/ - - optional - - weight - 1000 - - ^.*\.lproj/locversion.plist$ - - omit - - weight - 1100 - - ^version.plist$ - - - rules2 - - .*\.dSYM($|/) - - weight - 11 - - ^ - - weight - 20 - - ^(.*/)?\.DS_Store$ - - omit - - weight - 2000 - - ^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/ - - nested - - weight - 10 - - ^.* - - ^.*\.lproj/ - - optional - - weight - 1000 - - ^.*\.lproj/locversion.plist$ - - omit - - weight - 1100 - - ^Info\.plist$ - - omit - - weight - 20 - - ^PkgInfo$ - - omit - - weight - 20 - - ^[^/]+$ - - nested - - weight - 10 - - ^embedded\.provisionprofile$ - - weight - 20 - - ^version\.plist$ - - weight - 20 - - - - diff --git a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/_CodeSignature/CodeSignature b/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/_CodeSignature/CodeSignature deleted file mode 100644 index ccf87fae..00000000 Binary files a/samples/LFLiveKitFrameworkDemo/vendors/GPUImage.framework/_CodeSignature/CodeSignature and /dev/null differ diff --git a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Info.plist b/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Info.plist deleted file mode 100644 index 2fb44429..00000000 Binary files a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/Info.plist and /dev/null differ diff --git a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/_CodeSignature/CodeDirectory b/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/_CodeSignature/CodeDirectory deleted file mode 100644 index 3b56c5d7..00000000 Binary files a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/_CodeSignature/CodeDirectory and /dev/null differ diff --git a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/_CodeSignature/CodeRequirements b/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/_CodeSignature/CodeRequirements deleted file mode 100644 index cb010c30..00000000 Binary files a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/_CodeSignature/CodeRequirements and /dev/null differ diff --git a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/_CodeSignature/CodeRequirements-1 b/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/_CodeSignature/CodeRequirements-1 deleted file mode 100644 index f74186e1..00000000 Binary files a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/_CodeSignature/CodeRequirements-1 and /dev/null differ diff --git a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/_CodeSignature/CodeResources b/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/_CodeSignature/CodeResources deleted file mode 100644 index 4248fdcd..00000000 --- a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/_CodeSignature/CodeResources +++ /dev/null @@ -1,261 +0,0 @@ - - - - - files - - Headers/amf.h - - kGNvjJIoCw7nJy3kjjy6bgjrbVM= - - Headers/bytes.h - - rf2XeRlX/rLrVwSO4ygxJ9qcGGs= - - Headers/dh.h - - EZYLNyDbk3Xey+pkbfmAjzAsn1Q= - - Headers/dhgroups.h - - 1PArWQd8m0VVGjppiS9eF+7GqZQ= - - Headers/error.h - - BmXYGUcz+qLEYHOmNWm5iZs1cT0= - - Headers/handshake.h - - JSTLeAOP5Ux5RV0MuT6OlTWeM50= - - Headers/http.h - - D+7YvQh17K8IEHx9uY5mQkRolrQ= - - Headers/log.h - - smAML5qh1lQsa5O141/avkVpW/0= - - Headers/rtmp.h - - qjxjEHhY+ET2K4I9Fkp5NWvQ1ak= - - Headers/rtmp_sys.h - - h5aG2dXtze3bb6Ni5AzBEFNAIlw= - - Info.plist - - jBTUuQpeANWyu36KXLiUdaEFXR8= - - - files2 - - Headers/amf.h - - hash - - kGNvjJIoCw7nJy3kjjy6bgjrbVM= - - hash2 - - IwCiI2tTa5UbNIqujHh0Gat+ENoUqs0pfJQRlTgCXLI= - - - Headers/bytes.h - - hash - - rf2XeRlX/rLrVwSO4ygxJ9qcGGs= - - hash2 - - VdhSAgCQvn5k65JqlJ4XKX78jg0y4zj/eoIfVYxhU+c= - - - Headers/dh.h - - hash - - EZYLNyDbk3Xey+pkbfmAjzAsn1Q= - - hash2 - - pu/JXkXrTPMO789L5OBFn4sDi5H1Lnc0Af0i/w6lIuk= - - - Headers/dhgroups.h - - hash - - 1PArWQd8m0VVGjppiS9eF+7GqZQ= - - hash2 - - Sa1jUlQTNigFKQYgAVHsE9si09vjh5nGBAArSX7dLwU= - - - Headers/error.h - - hash - - BmXYGUcz+qLEYHOmNWm5iZs1cT0= - - hash2 - - 3L44UXfV0Oi5SY8OQh4tg9nOamJ5LfT5c+m5LOKs1f8= - - - Headers/handshake.h - - hash - - JSTLeAOP5Ux5RV0MuT6OlTWeM50= - - hash2 - - wYq3SY2KdCFex18QI6sRapiwAkCtOQpXtlExS884zUU= - - - Headers/http.h - - hash - - D+7YvQh17K8IEHx9uY5mQkRolrQ= - - hash2 - - KogyAaqwVHvADAzf/kuUHnDWbhuoYhTOV47tGjE5oCM= - - - Headers/log.h - - hash - - smAML5qh1lQsa5O141/avkVpW/0= - - hash2 - - 61apJ7aiRVG2Ojkg5hnHlkaiWGvXIiCySunTTfE7O64= - - - Headers/rtmp.h - - hash - - qjxjEHhY+ET2K4I9Fkp5NWvQ1ak= - - hash2 - - 5K1oNfNpC8lmSejtzpJAMPGKDRLYDF8UNJ2ZdFbMDhQ= - - - Headers/rtmp_sys.h - - hash - - h5aG2dXtze3bb6Ni5AzBEFNAIlw= - - hash2 - - qc8QOVfQ/MtdV8QCXQ27QID1M5nTNH13iWsGr2r8jSg= - - - - rules - - ^ - - ^.*\.lproj/ - - optional - - weight - 1000 - - ^.*\.lproj/locversion.plist$ - - omit - - weight - 1100 - - ^version.plist$ - - - rules2 - - .*\.dSYM($|/) - - weight - 11 - - ^ - - weight - 20 - - ^(.*/)?\.DS_Store$ - - omit - - weight - 2000 - - ^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/ - - nested - - weight - 10 - - ^.* - - ^.*\.lproj/ - - optional - - weight - 1000 - - ^.*\.lproj/locversion.plist$ - - omit - - weight - 1100 - - ^Info\.plist$ - - omit - - weight - 20 - - ^PkgInfo$ - - omit - - weight - 20 - - ^[^/]+$ - - nested - - weight - 10 - - ^embedded\.provisionprofile$ - - weight - 20 - - ^version\.plist$ - - weight - 20 - - - - diff --git a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/_CodeSignature/CodeSignature b/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/_CodeSignature/CodeSignature deleted file mode 100644 index 6fd9b074..00000000 Binary files a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/_CodeSignature/CodeSignature and /dev/null differ diff --git a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/pili-librtmp b/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/pili-librtmp deleted file mode 100644 index 84b2f407..00000000 Binary files a/samples/LFLiveKitFrameworkDemo/vendors/pili-librtmp.framework/pili-librtmp and /dev/null differ