├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── markdown-exported-files.xml
├── markdown-navigator.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── LICENSE.txt
├── aavt
├── .gitignore
├── bintrayUpload.gradle
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── wuwang
│ │ └── aavt
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ └── shader
│ │ │ ├── base.frag
│ │ │ ├── base.vert
│ │ │ ├── beauty
│ │ │ ├── beauty.frag
│ │ │ └── beauty.vert
│ │ │ ├── color
│ │ │ └── gray.frag
│ │ │ ├── convert
│ │ │ ├── eo_yuv420p.frag
│ │ │ ├── export_yuv.frag
│ │ │ ├── export_yuv420p.frag
│ │ │ └── export_yuv420sp.frag
│ │ │ ├── effect
│ │ │ ├── fluorescence.frag
│ │ │ ├── water_color.frag
│ │ │ └── water_color_step1.frag
│ │ │ ├── func
│ │ │ ├── candy.frag
│ │ │ ├── faltung3x3.frag
│ │ │ ├── gauss.frag
│ │ │ ├── sobel.frag
│ │ │ └── sobel2.frag
│ │ │ ├── oes.frag
│ │ │ └── oes.vert
│ ├── java
│ │ └── com
│ │ │ └── wuwang
│ │ │ └── aavt
│ │ │ ├── av
│ │ │ ├── CameraRecorder2.java
│ │ │ ├── Mp4Processor.java
│ │ │ ├── Mp4Processor2.java
│ │ │ ├── SurfaceRecorder.java
│ │ │ └── VideoCapture.java
│ │ │ ├── core
│ │ │ ├── IObservable.java
│ │ │ ├── IObserver.java
│ │ │ ├── Observable.java
│ │ │ └── Renderer.java
│ │ │ ├── egl
│ │ │ ├── EGLConfigAttrs.java
│ │ │ ├── EGLContextAttrs.java
│ │ │ └── EglHelper.java
│ │ │ ├── expend
│ │ │ └── SluggardFilterTool.java
│ │ │ ├── gl
│ │ │ ├── BaseFilter.java
│ │ │ ├── BaseFuncFilter.java
│ │ │ ├── BeautyFilter.java
│ │ │ ├── BlackMagicFilter.java
│ │ │ ├── CandyFilter.java
│ │ │ ├── Faltung3x3Filter.java
│ │ │ ├── FluorescenceFilter.java
│ │ │ ├── FrameBuffer.java
│ │ │ ├── GrayFilter.java
│ │ │ ├── GroupFilter.java
│ │ │ ├── LazyFilter.java
│ │ │ ├── OesFilter.java
│ │ │ ├── ProxyFilter.java
│ │ │ ├── RollFilter.java
│ │ │ ├── StickFigureFilter.java
│ │ │ ├── WaterColorFilter.java
│ │ │ ├── WaterMarkFilter.java
│ │ │ └── YuvOutputFilter.java
│ │ │ ├── log
│ │ │ ├── AvLog.java
│ │ │ ├── ConsoleLogger.java
│ │ │ ├── EmptyLogger.java
│ │ │ └── ILogger.java
│ │ │ ├── media
│ │ │ ├── CodecUtil.java
│ │ │ ├── MediaConfig.java
│ │ │ ├── RenderBean.java
│ │ │ ├── SoundRecorder.java
│ │ │ ├── SurfaceEncoder.java
│ │ │ ├── SurfaceShower.java
│ │ │ ├── VideoSurfaceProcessor.java
│ │ │ ├── WrapRenderer.java
│ │ │ ├── audio
│ │ │ │ ├── FileAudioProvider.java
│ │ │ │ ├── ISoundProvider.java
│ │ │ │ └── MicAudioProvider.java
│ │ │ ├── av
│ │ │ │ ├── AvException.java
│ │ │ │ ├── ICloseable.java
│ │ │ │ └── IStore.java
│ │ │ ├── hard
│ │ │ │ ├── HardMediaData.java
│ │ │ │ ├── IHardStore.java
│ │ │ │ ├── MediaMuxerWraper.java
│ │ │ │ ├── Mp4MuxStore.java
│ │ │ │ ├── Recycler.java
│ │ │ │ └── StrengthenMp4MuxStore.java
│ │ │ ├── player
│ │ │ │ ├── AudioDecoder.java
│ │ │ │ ├── AudioPlayer.java
│ │ │ │ ├── BaseAudioDecoder.java
│ │ │ │ ├── BaseVideoDecoder.java
│ │ │ │ ├── ByteBufferData.java
│ │ │ │ ├── EPlayerException.java
│ │ │ │ ├── EffectMediaPlayer.java
│ │ │ │ ├── EffectMediaView.java
│ │ │ │ ├── IAudioProcessor.java
│ │ │ │ ├── IDecoder.java
│ │ │ │ ├── ITextureProcessor.java
│ │ │ │ ├── ITimeObserver.java
│ │ │ │ ├── NormalAudioDecoder.java
│ │ │ │ ├── NormalVideoDecoder.java
│ │ │ │ └── VideoPlayer.java
│ │ │ └── video
│ │ │ │ ├── Camera2Provider.java
│ │ │ │ ├── CameraProvider.java
│ │ │ │ ├── ITextureProvider.java
│ │ │ │ └── Mp4Provider.java
│ │ │ └── utils
│ │ │ ├── GpuUtils.java
│ │ │ └── MatrixUtils.java
│ └── res
│ │ └── values
│ │ ├── attr.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── wuwang
│ └── aavt
│ └── ExampleUnitTest.java
├── build.gradle
├── examples
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── wuwang
│ │ └── aavt
│ │ └── examples
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── wuwang
│ │ │ └── aavt
│ │ │ └── examples
│ │ │ ├── CameraRecorderActivity.java
│ │ │ ├── ExampleMp4ProcessActivity.java
│ │ │ ├── GetPathFromUri4kitkat.java
│ │ │ ├── MainActivity.java
│ │ │ ├── PermissionAsker.java
│ │ │ ├── VideoPlayerActivity.java
│ │ │ ├── VideoUtils.java
│ │ │ └── YuvExportActivity.java
│ └── res
│ │ ├── drawable
│ │ └── tv_start_bg.xml
│ │ ├── layout
│ │ ├── activity__export_yuv.xml
│ │ ├── activity_camera_record.xml
│ │ ├── activity_main.xml
│ │ ├── activity_mp4.xml
│ │ └── activity_player.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── wuwang
│ └── aavt
│ └── examples
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── readme.md
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | /.idea/misc.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/.idea/markdown-exported-files.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | 1.8
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/aavt/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/aavt/bintrayUpload.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.github.dcendents.android-maven'
2 | apply plugin: 'com.jfrog.bintray'
3 | // 配置版本
4 | version = rootProject.ext.vName
5 |
6 | // 定义相关网站
7 | def siteUrl = 'https://github.com/doggycoder/AAVT' // 项目的主页
8 | def gitUrl = 'https://github.com/doggycoder/AAVT.git'
9 | group = "com.wuwang.aavt"
10 |
11 | install {
12 | repositories.mavenInstaller {
13 | // This generates POM.xml with proper parameters
14 | pom {
15 | project {
16 | packaging 'aar'
17 | // Add your description here
18 | name 'Aavt'
19 | url siteUrl
20 | // Set your license
21 | licenses {
22 | license {
23 | name 'The Apache Software License, Version 2.0'
24 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
25 | }
26 | }
27 | developers {
28 | developer {
29 | id 'doggycoder' //填写的一些基本信息
30 | name 'doggycoder'
31 | email '158183202@qq.com' // 填写邮箱
32 | }
33 | }
34 | scm {
35 | connection gitUrl
36 | developerConnection gitUrl
37 | url siteUrl
38 | }
39 | }
40 | }
41 | }
42 | }
43 |
44 | // 打包 javadocjar 和 sourcejar
45 | task sourcesJar(type: Jar) {
46 | from android.sourceSets.main.java.srcDirs
47 | classifier = 'sources'
48 | }
49 | task javadoc(type: Javadoc) {
50 | source = android.sourceSets.main.java.srcDirs
51 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
52 | }
53 | task javadocJar(type: Jar, dependsOn: javadoc) {
54 | classifier = 'javadoc'
55 | from javadoc.destinationDir
56 | }
57 | artifacts {
58 | archives javadocJar
59 | archives sourcesJar
60 | }
61 | def propertiesFile = project.rootProject.file('local.properties')
62 | if(propertiesFile.exists()){
63 | Properties properties = new Properties()
64 | properties.load(propertiesFile.newDataInputStream())
65 | bintray {
66 | user = properties.getProperty("bintray.user")
67 | key = properties.getProperty("bintray.apikey")
68 | configurations = ['archives']
69 | pkg {
70 | repo = "maven"
71 | name = "Aavt" //发布到JCenter上的项目名字
72 | websiteUrl = siteUrl
73 | vcsUrl = gitUrl
74 | licenses = ["Apache-2.0"]
75 | publish = true
76 | }
77 | }
78 | }
79 |
80 | javadoc { //jav doc采用utf-8编码否则会报“GBK的不可映射字符”错误
81 | options{
82 | encoding "UTF-8"
83 | charSet 'UTF-8'
84 | links "http://docs.oracle.com/javase/7/docs/api"
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/aavt/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.wuwang.aavt'
4 |
5 | android {
6 | compileSdkVersion 25
7 |
8 | defaultConfig {
9 | minSdkVersion 14
10 | targetSdkVersion 25
11 | versionCode rootProject.ext.vCode
12 | versionName rootProject.ext.vName
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | task buildMyJar(type: Jar, dependsOn: ['build']) {
26 | //导出的jar文件名称
27 | archiveName = 'Aavt.jar'
28 | //从哪个目录打包jar
29 | from('build/intermediates/classes/release/')
30 | destinationDir = file('output')
31 | //去掉不要的类
32 | exclude('**/BuildConfig.class')
33 | exclude('**/BuildConfig\$*.class')
34 | exclude('**/R.class')
35 | exclude('**/R\$*.class')
36 | include('com/wuwang/aavt/**')
37 |
38 | // doLast{
39 | // copy {
40 | // from('libs/','build/intermediates/cmake/release/obj/')
41 | // into('output/')
42 | // }
43 | // }
44 | }
45 |
46 | dependencies {
47 | implementation fileTree(dir: 'libs', include: ['*.jar'])
48 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
49 | exclude group: 'com.android.support', module: 'support-annotations'
50 | })
51 | implementation 'com.android.support:appcompat-v7:25.3.1'
52 | testImplementation 'junit:junit:4.12'
53 | }
54 |
55 | apply from: "bintrayUpload.gradle"
56 |
--------------------------------------------------------------------------------
/aavt/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/aavt/src/androidTest/java/com/wuwang/aavt/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.wuwang.aavt;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.wuwang.aavt.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/aavt/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/base.frag:
--------------------------------------------------------------------------------
1 | precision mediump float;
2 | varying vec2 vTextureCo;
3 | uniform sampler2D uTexture;
4 | void main() {
5 | gl_FragColor = texture2D( uTexture, vTextureCo);
6 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/base.vert:
--------------------------------------------------------------------------------
1 | precision highp float;
2 | precision highp int;
3 | attribute vec4 aVertexCo;
4 | attribute vec2 aTextureCo;
5 |
6 | uniform mat4 uVertexMatrix;
7 | uniform mat4 uTextureMatrix;
8 |
9 | varying vec2 vTextureCo;
10 |
11 | void main(){
12 | gl_Position = uVertexMatrix*aVertexCo;
13 | vTextureCo = (uTextureMatrix*vec4(aTextureCo,0,1)).xy;
14 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/beauty/beauty.frag:
--------------------------------------------------------------------------------
1 | precision highp float;
2 | precision highp int;
3 | uniform sampler2D uTexture;
4 | uniform int uIternum;
5 | uniform float uACoef; //参数
6 | uniform float uMixCoef; //混合系数
7 | varying highp vec2 vTextureCo;
8 | varying highp vec2 vBlurCoord1s[14];
9 | const float distanceNormalizationFactor = 4.0;
10 | const mat3 saturateMatrix = mat3(1.1102,-0.0598,-0.061,-0.0774,1.0826,-0.1186,-0.0228,-0.0228,1.1772);
11 |
12 | void main() {
13 |
14 | vec3 centralColor;
15 | float central;
16 | float gaussianWeightTotal;
17 | float sum;
18 | float sampleColor;
19 | float distanceFromCentralColor;
20 | float gaussianWeight;
21 |
22 | central = texture2D( uTexture, vTextureCo ).g;
23 | gaussianWeightTotal = 0.2;
24 | sum = central * 0.2;
25 |
26 | for (int i = 0; i < 6; i++) {
27 | sampleColor = texture2D( uTexture, vBlurCoord1s[i] ).g;
28 | distanceFromCentralColor = min( abs( central - sampleColor ) * distanceNormalizationFactor, 1.0 );
29 | gaussianWeight = 0.05 * (1.0 - distanceFromCentralColor);
30 | gaussianWeightTotal += gaussianWeight;
31 | sum += sampleColor * gaussianWeight;
32 | }
33 | for (int i = 6; i < 14; i++) {
34 | sampleColor = texture2D( uTexture, vBlurCoord1s[i] ).g;
35 | distanceFromCentralColor = min( abs( central - sampleColor ) * distanceNormalizationFactor, 1.0 );
36 | gaussianWeight = 0.1 * (1.0 - distanceFromCentralColor);
37 | gaussianWeightTotal += gaussianWeight;
38 | sum += sampleColor * gaussianWeight;
39 | }
40 |
41 | sum = sum / gaussianWeightTotal;
42 | centralColor = texture2D( uTexture, vTextureCo ).rgb;
43 | sampleColor = centralColor.g - sum + 0.5;
44 | for (int i = 0; i < 100; i++) {
45 | if(i>=uIternum){
46 | break;
47 | }
48 | if (sampleColor <= 0.5) {
49 | sampleColor = sampleColor * sampleColor * 2.0;
50 | }
51 | else {
52 | sampleColor = 1.0 - ((1.0 - sampleColor)*(1.0 - sampleColor) * 2.0);
53 | }
54 | }
55 |
56 | float aa = 1.0 + pow( centralColor.g, 0.3 )*uACoef;
57 | vec3 smoothColor = centralColor*aa - vec3( sampleColor )*(aa - 1.0);
58 | smoothColor = clamp( smoothColor, vec3( 0.0 ), vec3( 1.0 ) );
59 | smoothColor = mix( centralColor, smoothColor, pow( centralColor.g, 0.33 ) );
60 | smoothColor = mix( centralColor, smoothColor, pow( centralColor.g, uMixCoef ) );
61 | gl_FragColor = vec4( pow( smoothColor, vec3( 0.96 ) ), 1.0 );
62 | vec3 satcolor = gl_FragColor.rgb * saturateMatrix;
63 | gl_FragColor.rgb = mix( gl_FragColor.rgb, satcolor, 0.23 );
64 |
65 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/beauty/beauty.vert:
--------------------------------------------------------------------------------
1 | attribute vec4 aVertexCo;
2 | attribute vec2 aTextureCo;
3 | varying vec2 vTextureCo;
4 | varying vec2 vBlurCoord1s[14];
5 | uniform float uWidth;
6 | uniform float uHeight;
7 | uniform mat4 uVertexMatrix;
8 | uniform mat4 uTextureMatrix;
9 | void main()
10 | {
11 | gl_Position = uVertexMatrix*aVertexCo;
12 | vTextureCo = (uTextureMatrix*vec4(aTextureCo,0,1)).xy;
13 |
14 | highp float mul_x = 2.0 / uWidth;
15 | highp float mul_y = 2.0 / uHeight;
16 |
17 | vBlurCoord1s[0] = vTextureCo + vec2( 0.0 * mul_x, -10.0 * mul_y );
18 | vBlurCoord1s[1] = vTextureCo + vec2( 8.0 * mul_x, -5.0 * mul_y );
19 | vBlurCoord1s[2] = vTextureCo + vec2( 8.0 * mul_x, 5.0 * mul_y );
20 | vBlurCoord1s[3] = aTextureCo + vec2( 0.0 * mul_x, 10.0 * mul_y );
21 | vBlurCoord1s[4] = aTextureCo + vec2( -8.0 * mul_x, 5.0 * mul_y );
22 | vBlurCoord1s[5] = aTextureCo + vec2( -8.0 * mul_x, -5.0 * mul_y );
23 |
24 | mul_x = 1.2 / uWidth;
25 | mul_y = 1.2 / uHeight;
26 |
27 | vBlurCoord1s[6] = aTextureCo + vec2( 0.0 * mul_x, -6.0 * mul_y );
28 | vBlurCoord1s[7] = aTextureCo + vec2( -4.0 * mul_x, -4.0 * mul_y );
29 | vBlurCoord1s[8] = aTextureCo + vec2( -6.0 * mul_x, 0.0 * mul_y );
30 | vBlurCoord1s[9] = aTextureCo + vec2( -4.0 * mul_x, 4.0 * mul_y );
31 | vBlurCoord1s[10] = aTextureCo + vec2( 0.0 * mul_x, 6.0 * mul_y );
32 | vBlurCoord1s[11] = aTextureCo + vec2( 4.0 * mul_x, 4.0 * mul_y );
33 | vBlurCoord1s[12] = aTextureCo + vec2( 6.0 * mul_x, 0.0 * mul_y );
34 | vBlurCoord1s[13] = aTextureCo + vec2( 4.0 * mul_x, -4.0 * mul_y );
35 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/color/gray.frag:
--------------------------------------------------------------------------------
1 | precision mediump float;
2 | varying vec2 vTextureCo;
3 | uniform sampler2D uTexture;
4 | const highp vec3 CO = vec3(0.2125, 0.7154, 0.0721);
5 |
6 | void main() {
7 | gl_FragColor=vec4(vec3(dot(texture2D( uTexture, vTextureCo).rgb,CO)),1.0);
8 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/convert/eo_yuv420p.frag:
--------------------------------------------------------------------------------
1 | precision highp float;
2 | precision highp int;
3 |
4 | varying vec2 vTextureCo;
5 | uniform sampler2D uTexture;
6 |
7 | //为了简化计算,宽高都必须为8的倍数
8 | uniform float uWidth; // 纹理宽
9 | uniform float uHeight; // 纹理高
10 |
11 | //转换公式
12 | //Y’= 0.299*R’ + 0.587*G’ + 0.114*B’
13 | //U’= -0.147*R’ - 0.289*G’ + 0.436*B’ = 0.492*(B’- Y’)
14 | //V’= 0.615*R’ - 0.515*G’ - 0.100*B’ = 0.877*(R’- Y’)
15 | //导出原理:采样坐标只作为确定输出位置使用,通过输出纹理计算实际采样位置,进行采样和并转换,
16 | //然后将转换的结果填充到输出位置
17 |
18 | float cY(float x,float y){
19 | vec4 c=texture2D(uTexture,vec2(x,y));
20 | return c.r*0.2990+c.g*0.5870+c.b*0.1140;
21 | }
22 |
23 | float cU(float x,float y){
24 | vec4 c=texture2D(uTexture,vec2(x,y));
25 | return -0.1471*c.r - 0.2889*c.g + 0.4360*c.b+0.5000;
26 | }
27 |
28 | float cV(float x,float y){
29 | vec4 c=texture2D(uTexture,vec2(x,y));
30 | return 0.6150*c.r - 0.5150*c.g - 0.1000*c.b+0.5000;
31 | }
32 |
33 | vec2 cPos(float t,float shiftx,float gy){
34 | vec2 pos=vec2(floor(uWidth*vTextureCo.x),floor(uHeight*gy));
35 | return vec2(mod(pos.x*shiftx,uWidth),(pos.y*shiftx+floor(pos.x*shiftx/uWidth))*t);
36 | }
37 |
38 | //Y分量的计算
39 | vec4 calculateY(){
40 | vec2 pos=cPos(1.,4.,vTextureCo.y);
41 | vec4 oColor=vec4(0);
42 | float textureYPos=pos.y/uHeight;
43 | oColor[0]=cY(pos.x/uWidth,textureYPos);
44 | oColor[1]=cY((pos.x+1.)/uWidth,textureYPos);
45 | oColor[2]=cY((pos.x+2.)/uWidth,textureYPos);
46 | oColor[3]=cY((pos.x+3.)/uWidth,textureYPos);
47 | return oColor;
48 | }
49 |
50 | //U分量的计算
51 | vec4 calculateU(){
52 | vec2 pos=cPos(2.,8.,vTextureCo.y-0.2500);
53 | vec4 oColor=vec4(0);
54 | float textureYPos=pos.y/uHeight;
55 | oColor[0]= cU(pos.x/uWidth,textureYPos);
56 | oColor[1]= cU((pos.x+2.)/uWidth,textureYPos);
57 | oColor[2]= cU((pos.x+4.)/uWidth,textureYPos);
58 | oColor[3]= cU((pos.x+6.)/uWidth,textureYPos);
59 | return oColor;
60 | }
61 |
62 | //V分量计算
63 | vec4 calculateV(){
64 | vec2 pos=cPos(2.,8.,vTextureCo.y-0.3125);
65 | vec4 oColor=vec4(0);
66 | float textureYPos=pos.y/uHeight;
67 | oColor[0]=cV(pos.x/uWidth,textureYPos);
68 | oColor[1]=cV((pos.x+2.)/uWidth,textureYPos);
69 | oColor[2]=cV((pos.x+4.)/uWidth,textureYPos);
70 | oColor[3]=cV((pos.x+6.)/uWidth,textureYPos);
71 | return oColor;
72 | }
73 |
74 | //UV的计算,YUV420SP用,test
75 | vec4 calculateUV(){
76 | vec2 pos=cPos(2.,4.,vTextureCo.y-0.2500);
77 | vec4 oColor=vec4(0);
78 | float textureYPos=pos.y/uHeight;
79 | oColor[0]= cU(pos.x/uWidth,textureYPos);
80 | oColor[1]= cV(pos.x/uWidth,textureYPos);
81 | oColor[2]= cU((pos.x+2.)/uWidth,textureYPos);
82 | oColor[3]= cV((pos.x+2.)/uWidth,textureYPos);
83 | return oColor;
84 | }
85 |
86 | void main() {
87 | if(vTextureCo.y<0.2500){
88 | gl_FragColor=calculateY();
89 | }else if(vTextureCo.y<0.3125){
90 | gl_FragColor=calculateU();
91 | }else if(vTextureCo.y<0.3750){
92 | gl_FragColor=calculateV();
93 | }else{
94 | gl_FragColor=vec4(0,0,0,0);
95 | }
96 | //gl_FragColor=vec4(rPosX/uWidth,rPosY/uHeight,rPosX/uWidth,rPosY/uHeight);
97 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/convert/export_yuv.frag:
--------------------------------------------------------------------------------
1 | precision highp float;
2 | precision highp int;
3 |
4 | varying vec2 vTextureCo;
5 | uniform sampler2D uTexture;
6 |
7 | uniform float uWidth;
8 | uniform float uHeight;
9 |
10 | float cY(float x,float y){
11 | vec4 c=texture2D(uTexture,vec2(x,y));
12 | return c.r*0.2126+c.g*0.7152+c.b*0.0722;
13 | }
14 |
15 | vec4 cC(float x,float y,float dx,float dy){
16 | vec4 c0=texture2D(uTexture,vec2(x,y));
17 | vec4 c1=texture2D(uTexture,vec2(x+dx,y));
18 | vec4 c2=texture2D(uTexture,vec2(x,y+dy));
19 | vec4 c3=texture2D(uTexture,vec2(x+dx,y+dy));
20 | return (c0+c1+c2+c3)/4.;
21 | }
22 |
23 | float cU(float x,float y,float dx,float dy){
24 | vec4 c=cC(x,y,dx,dy);
25 | return -0.09991*c.r - 0.33609*c.g + 0.43600*c.b+0.5000;
26 | }
27 |
28 | float cV(float x,float y,float dx,float dy){
29 | vec4 c=cC(x,y,dx,dy);
30 | return 0.61500*c.r - 0.55861*c.g - 0.05639*c.b+0.5000;
31 | }
32 |
33 | vec2 cPos(float t,float shiftx,float gy){
34 | vec2 pos=vec2(floor(uWidth*vTextureCo.x),floor(uHeight*gy));
35 | return vec2(mod(pos.x*shiftx,uWidth),(pos.y*shiftx+floor(pos.x*shiftx/uWidth))*t);
36 | }
37 |
38 | vec4 calculateY(){
39 | vec2 pos=cPos(1.,4.,vTextureCo.y);
40 | vec4 oColor=vec4(0);
41 | float textureYPos=pos.y/uHeight;
42 | oColor[0]=cY(pos.x/uWidth,textureYPos);
43 | oColor[1]=cY((pos.x+1.)/uWidth,textureYPos);
44 | oColor[2]=cY((pos.x+2.)/uWidth,textureYPos);
45 | oColor[3]=cY((pos.x+3.)/uWidth,textureYPos);
46 | return oColor;
47 | }
48 | vec4 calculateU(float gy,float dx,float dy){
49 | vec2 pos=cPos(2.,8.,vTextureCo.y-gy);
50 | vec4 oColor=vec4(0);
51 | float textureYPos=pos.y/uHeight;
52 | oColor[0]= cU(pos.x/uWidth,textureYPos,dx,dy);
53 | oColor[1]= cU((pos.x+2.)/uWidth,textureYPos,dx,dy);
54 | oColor[2]= cU((pos.x+4.)/uWidth,textureYPos,dx,dy);
55 | oColor[3]= cU((pos.x+6.)/uWidth,textureYPos,dx,dy);
56 | return oColor;
57 | }
58 | vec4 calculateV(float gy,float dx,float dy){
59 | vec2 pos=cPos(2.,8.,vTextureCo.y-gy);
60 | vec4 oColor=vec4(0);
61 | float textureYPos=pos.y/uHeight;
62 | oColor[0]=cV(pos.x/uWidth,textureYPos,dx,dy);
63 | oColor[1]=cV((pos.x+2.)/uWidth,textureYPos,dx,dy);
64 | oColor[2]=cV((pos.x+4.)/uWidth,textureYPos,dx,dy);
65 | oColor[3]=cV((pos.x+6.)/uWidth,textureYPos,dx,dy);
66 | return oColor;
67 | }
68 | vec4 calculateUV(float dx,float dy){
69 | vec2 pos=cPos(2.,4.,vTextureCo.y-0.2500);
70 | vec4 oColor=vec4(0);
71 | float textureYPos=pos.y/uHeight;
72 | oColor[0]= cU(pos.x/uWidth,textureYPos,dx,dy);
73 | oColor[1]= cV(pos.x/uWidth,textureYPos,dx,dy);
74 | oColor[2]= cU((pos.x+2.)/uWidth,textureYPos,dx,dy);
75 | oColor[3]= cV((pos.x+2.)/uWidth,textureYPos,dx,dy);
76 | return oColor;
77 | }
78 | vec4 calculateVU(float dx,float dy){
79 | vec2 pos=cPos(2.,4.,vTextureCo.y-0.2500);
80 | vec4 oColor=vec4(0);
81 | float textureYPos=pos.y/uHeight;
82 | oColor[0]= cV(pos.x/uWidth,textureYPos,dx,dy);
83 | oColor[1]= cU(pos.x/uWidth,textureYPos,dx,dy);
84 | oColor[2]= cV((pos.x+2.)/uWidth,textureYPos,dx,dy);
85 | oColor[3]= cU((pos.x+2.)/uWidth,textureYPos,dx,dy);
86 | return oColor;
87 | }
88 |
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/convert/export_yuv420p.frag:
--------------------------------------------------------------------------------
1 | precision highp float;
2 | precision highp int;
3 |
4 | varying vec2 vTextureCo;
5 | uniform sampler2D uTexture;
6 |
7 | //为了简化计算,宽高都必须为8的倍数
8 | uniform float uWidth; // 纹理宽
9 | uniform float uHeight; // 纹理高
10 |
11 | //转换公式
12 | //Y’= 0.299*R’ + 0.587*G’ + 0.114*B’
13 | //U’= -0.147*R’ - 0.289*G’ + 0.436*B’ = 0.492*(B’- Y’)
14 | //V’= 0.615*R’ - 0.515*G’ - 0.100*B’ = 0.877*(R’- Y’)
15 | //导出原理:采样坐标只作为确定输出位置使用,通过输出纹理计算实际采样位置,进行采样和并转换,
16 | //然后将转换的结果填充到输出位置
17 |
18 | float cY(float x,float y){
19 | vec4 c=texture2D(uTexture,vec2(x,y));
20 | return c.r*0.2990+c.g*0.5870+c.b*0.1140;
21 | }
22 |
23 | float cU(float x,float y){
24 | vec4 c=texture2D(uTexture,vec2(x,y));
25 | return -0.1471*c.r - 0.2889*c.g + 0.4360*c.b+0.5000;
26 | }
27 |
28 | float cV(float x,float y){
29 | vec4 c=texture2D(uTexture,vec2(x,y));
30 | return 0.6150*c.r - 0.5150*c.g - 0.1000*c.b+0.5000;
31 | }
32 |
33 | vec2 cPos(float t,float shiftx,float shifty){
34 | vec2 pos=vec2(uWidth*vTextureCo.x,uHeight*(vTextureCo-shifty));
35 | return vec2(mod(pos.x*shiftx,uWidth),(pos.y*shiftx+floor(pos.x*shiftx/uWidth))*t);
36 | }
37 |
38 | //Y分量的计算
39 | vec4 calculateY(){
40 | //填充点对应图片的位置
41 | float posX=floor(uWidth*vTextureCo.x);
42 | float posY=floor(uHeight*vTextureCo.y);
43 | //实际采样起始点对应图片的位置
44 | float rPosX=mod(posX*4.,uWidth);
45 | float rPosY=posY*4.+floor(posX*4./uWidth);
46 | vec4 oColor=vec4(0);
47 | float textureYPos=rPosY/uHeight;
48 | oColor[0]=cY(rPosX/uWidth,textureYPos);
49 | oColor[1]=cY((rPosX+1.)/uWidth,textureYPos);
50 | oColor[2]=cY((rPosX+2.)/uWidth,textureYPos);
51 | oColor[3]=cY((rPosX+3.)/uWidth,textureYPos);
52 | return oColor;
53 | }
54 |
55 |
56 | //U分量的计算
57 | vec4 calculateU(){
58 | //U的采样,宽度是1:8,高度是1:2,U的位置高度偏移了1/4,一个点是4个U,采样区域是宽高位8*2
59 | float posX=floor(uWidth*vTextureCo.x);
60 | float posY=floor(uHeight*(vTextureCo.y-0.2500));
61 | //实际采样起始点对应图片的位置
62 | float rPosX=mod(posX*8.,uWidth);
63 | float rPosY=posY*16.+floor(posX*8./uWidth)*2.;
64 |
65 | vec4 oColor=vec4(0);
66 | oColor[0]= cU(rPosX/uWidth,rPosY/uHeight);
67 | oColor[1]= cU((rPosX+2.)/uWidth,rPosY/uHeight);
68 | oColor[2]= cU((rPosX+4.)/uWidth,rPosY/uHeight);
69 | oColor[3]= cU((rPosX+6.)/uWidth,rPosY/uHeight);
70 | return oColor;
71 | }
72 |
73 | //V分量计算
74 | vec4 calculateV(){
75 | //V的采样,宽度是1:8,高度是1:2,U的位置高度偏移了1/4,一个点是4个V,采样区域是宽高位8*2
76 | float posX=floor(uWidth*vTextureCo.x);
77 | float posY=floor(uHeight*(vTextureCo.y-0.3125));
78 | //实际采样起始点对应图片的位置
79 | float rPosX=mod(posX*8.,uWidth);
80 | float rPosY=posY*16.+floor(posX*8./uWidth)*2.;
81 |
82 | vec4 oColor=vec4(0);
83 | oColor[0]=cV(rPosX/uWidth,rPosY/uHeight);
84 | oColor[1]=cV((rPosX+2.)/uWidth,rPosY/uHeight);
85 | oColor[2]=cV((rPosX+4.)/uWidth,rPosY/uHeight);
86 | oColor[3]=cV((rPosX+6.)/uWidth,rPosY/uHeight);
87 | return oColor;
88 | }
89 |
90 | //UV的计算,YUV420SP用,test
91 | vec4 calculateUV(){
92 | float posX=floor(uWidth*vTextureCo.x);
93 | float posY=floor(uHeight*(vTextureCo.y-0.2500));
94 | //实际采样起始点对应图片的位置
95 | float rPosX=mod(posX*4.,uWidth);
96 | float rPosY=posY*8.+floor(posX*4./uWidth)*2.;
97 | vec4 oColor=vec4(0);
98 | oColor[0]= cU((rPosX+1.)/uWidth,(rPosY+1.)/uHeight);
99 | oColor[1]= cV((rPosX+1.)/uWidth,(rPosY+1.)/uHeight);
100 | oColor[2]= cU((rPosX+3.)/uWidth,(rPosY+1.)/uHeight);
101 | oColor[3]= cV((rPosX+3.)/uWidth,(rPosY+1.)/uHeight);
102 | return oColor;
103 | }
104 |
105 | void main() {
106 | if(vTextureCo.y<0.2500){
107 | gl_FragColor=calculateY();
108 | }else if(vTextureCo.y<0.3125){
109 | gl_FragColor=calculateU();
110 | }else if(vTextureCo.y<0.3750){
111 | gl_FragColor=calculateV();
112 | }else{
113 | gl_FragColor=vec4(0,0,0,0);
114 | }
115 | //gl_FragColor=vec4(rPosX/uWidth,rPosY/uHeight,rPosX/uWidth,rPosY/uHeight);
116 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/convert/export_yuv420sp.frag:
--------------------------------------------------------------------------------
1 | precision highp float;
2 | precision highp int;
3 |
4 | varying vec2 vTextureCo;
5 | uniform sampler2D uTexture;
6 |
7 | //为了简化计算,宽高都必须为8的倍数
8 | uniform float uWidth; // 纹理宽
9 | uniform float uHeight; // 纹理高
10 |
11 | //转换公式
12 | //Y’= 0.299*R’ + 0.587*G’ + 0.114*B’
13 | //U’= -0.147*R’ - 0.289*G’ + 0.436*B’ = 0.492*(B’- Y’)
14 | //V’= 0.615*R’ - 0.515*G’ - 0.100*B’ = 0.877*(R’- Y’)
15 | //导出原理:采样坐标只作为确定输出位置使用,通过输出纹理计算实际采样位置,进行采样和并转换,
16 | //然后将转换的结果填充到输出位置
17 |
18 | float cY(float x,float y){
19 | vec4 c=texture2D(uTexture,vec2(x,y));
20 | return c.r*0.2990+c.g*0.5870+c.b*0.1140;
21 | }
22 |
23 | float cU(float x,float y){
24 | vec4 c=texture2D(uTexture,vec2(x,y));
25 | return -0.1471*c.r - 0.2889*c.g + 0.4360*c.b+0.5000;
26 | }
27 |
28 | float cV(float x,float y){
29 | vec4 c=texture2D(uTexture,vec2(x,y));
30 | return 0.6150*c.r - 0.5150*c.g - 0.1000*c.b+0.5000;
31 | }
32 |
33 | vec2 cPos(float t,float shiftx,float shifty){
34 | vec2 pos=vec2(uWidth*vTextureCo.x,uHeight*(vTextureCo-shifty));
35 | return vec2(mod(pos.x*shiftx,uWidth),(pos.y*shiftx+floor(pos.x*shiftx/uWidth))*t);
36 | }
37 |
38 | //Y分量的计算
39 | vec4 calculateY(){
40 | //填充点对应图片的位置
41 | float posX=floor(uWidth*vTextureCo.x);
42 | float posY=floor(uHeight*vTextureCo.y);
43 | //实际采样起始点对应图片的位置
44 | float rPosX=mod(posX*4.,uWidth);
45 | float rPosY=posY*4.+floor(posX*4./uWidth);
46 | vec4 oColor=vec4(0);
47 | float textureYPos=rPosY/uHeight;
48 | oColor[0]=cY(rPosX/uWidth,textureYPos);
49 | oColor[1]=cY((rPosX+1.)/uWidth,textureYPos);
50 | oColor[2]=cY((rPosX+2.)/uWidth,textureYPos);
51 | oColor[3]=cY((rPosX+3.)/uWidth,textureYPos);
52 | return oColor;
53 | }
54 | gi git
55 | void main() {
56 | if(vTextureCo.y<0.2500){
57 | gl_FragColor=calculateY();
58 | }else if(vTextureCo.y<0.3750){
59 | gl_FragColor=calculateUV();
60 | }else{
61 | gl_FragColor=vec4(0,0,0,0);
62 | }
63 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/effect/fluorescence.frag:
--------------------------------------------------------------------------------
1 | precision highp float;
2 |
3 | uniform sampler2D uTexture;
4 | uniform sampler2D uTexture2;
5 | uniform float uWidth;
6 | uniform float uHeight;
7 | varying vec2 vTextureCo;
8 |
9 | uniform vec4 uBorderColor;
10 | uniform float uStep;
11 |
12 | void main(){
13 | vec4 baseColor=texture2D(uTexture,vTextureCo);
14 | float sobelColor=texture2D(uTexture2,vTextureCo).r;
15 | gl_FragColor=(1.-sobelColor*uStep)*baseColor+sobelColor*uBorderColor*uStep;
16 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/effect/water_color.frag:
--------------------------------------------------------------------------------
1 | precision mediump float;
2 |
3 | uniform sampler2D uTexture;
4 | uniform sampler2D uNoiseTexture;
5 | uniform float uWidth;
6 | uniform float uHeight;
7 | varying vec2 vTextureCo;
8 |
9 | vec4 valueAdd(vec2 pos,float shiftX,float shiftY,float p){
10 | vec2 newPos=vec2((pos.x+shiftX)/uWidth,(pos.y+shiftY)/uHeight);
11 | return texture2D(uTexture,newPos)/p;
12 | }
13 |
14 | void main(){
15 | float step=floor(uWidth/128.);
16 | vec2 xy = vec2(vTextureCo.x * uWidth, vTextureCo.y * uHeight);
17 | vec4 color=valueAdd(xy,0.,0.,4.);
18 | color+=valueAdd(xy,-step,-step,16.);
19 | color+=valueAdd(xy,-step,step,8.);
20 | color+=valueAdd(xy,-step,step,16.);
21 | color+=valueAdd(xy,step,-step,8.);
22 | color+=valueAdd(xy,step,step,8.);
23 | color+=valueAdd(xy,step,-step,16.);
24 | color+=valueAdd(xy,step,step,8.);
25 | color+=valueAdd(xy,step,step,16.);
26 | gl_FragColor = color;
27 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/effect/water_color_step1.frag:
--------------------------------------------------------------------------------
1 | precision mediump float;
2 |
3 | uniform sampler2D uTexture;
4 | uniform sampler2D uNoiseTexture;
5 | uniform float uWidth;
6 | uniform float uHeight;
7 | varying vec2 vTextureCo;
8 |
9 | vec4 quant(vec4 cl, float n) {
10 | cl.x = floor(cl.x * 255./n)*n/255.;
11 | cl.y = floor(cl.y * 255./n)*n/255.;
12 | cl.z = floor(cl.z * 255./n)*n/255.;
13 |
14 | return cl;
15 | }
16 |
17 | void main(void){
18 | vec4 noiseColor = texture2D(uNoiseTexture, vTextureCo);
19 | vec2 newUV = vec2(vTextureCo.x + noiseColor.x / uWidth, vTextureCo.y + noiseColor.y / uHeight);
20 | vec4 fColor = texture2D(uTexture, newUV);
21 |
22 | vec4 color = quant(fColor, 255./pow(2., 4.));
23 | //vec4 color = vec4(1., 1., .5, 1.);
24 | gl_FragColor = color;
25 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/func/candy.frag:
--------------------------------------------------------------------------------
1 | precision highp float;
2 |
3 | uniform sampler2D uTexture;
4 | uniform float uWidth;
5 | uniform float uHeight;
6 | varying vec2 vTextureCo;
7 | const float step=1.;
8 | const mat3 GX=mat3(-1.,0., +1., -2., 0., +2., -1., 0., +1.);
9 | const mat3 GY=mat3(-1., -2., -1., 0., 0., 0., +1., +2., +1.);
10 |
11 | //sobel 算子有两个滤波矩阵Gx和Gy,注意:
12 | //边缘检测时Gx为检测纵向边缘,Gy为检测横向边缘
13 | //计算法线时Gx为计算法线的横向偏移,Gy为计算法线的纵向偏移
14 | //Gx为[-1 0 +1 -2 0 +2 -1 0 +1] 3*3矩阵
15 | //Gy为[-1 -2 -1 0 0 0 +1 +2 +1] 3*3矩阵
16 |
17 | //candy 最主要的是在sobel的基础上做非最大值抑制
18 | //非最大值抑制前,先要更具Gx和Gy得到强度梯度
19 |
20 | float colorR(vec2 center,float shiftX,float shiftY){
21 | return texture2D(uTexture,vec2(vTextureCo.x+shiftX/uWidth,vTextureCo.y+shiftY/uHeight)).r;
22 | }
23 |
24 | void main(){
25 | vec2 center=vec2(vTextureCo.x*uWidth,vTextureCo.y*uHeight);
26 | float leftTop=colorR(center,-step,-step);
27 | float centerTop=colorR(center,0.,-step);
28 | float rightTop=colorR(center,step,-step);
29 | float leftCenter=colorR(center,-step,0.);
30 | float rightCenter=colorR(center,step,0.);
31 | float leftBottom=colorR(center,-step,step);
32 | float centerBottom=colorR(center,0.,step);
33 | float rightBottom=colorR(center,step,step);
34 | mat3 d=mat3(colorR(center,-step,-step),colorR(center,0.,-step),colorR(center,step,-step),
35 | colorR(center,-step,0.),colorR(center,0.,0.),colorR(center,step,0.),
36 | colorR(center,-step,step),colorR(center,0.,step),colorR(center,step,step));
37 | //计算Gx Gy
38 | float x = d[0][0]*GX[0][0]+d[1][0]*GX[1][0]+d[2][0]*GX[2][0]+
39 | d[0][1]*GX[0][1]+d[1][1]*GX[1][1]+d[2][1]*GX[2][1]+
40 | d[0][2]*GX[0][2]+d[1][2]*GX[1][2]+d[2][2]*GX[2][2];
41 | float y = d[0][0]*GY[0][0]+d[1][0]*GY[1][0]+d[2][0]*GY[2][0]+
42 | d[0][1]*GY[0][1]+d[1][1]*GY[1][1]+d[2][1]*GY[2][1]+
43 | d[0][2]*GY[0][2]+d[1][2]*GY[1][2]+d[2][2]*GY[2][2];
44 |
45 | //计算强度梯度
46 | float G=length(vec2(x,y));
47 | float thita=atan(y,x);
48 | gl_FragColor=vec4(vec3(G),1.);
49 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/func/faltung3x3.frag:
--------------------------------------------------------------------------------
1 | precision mediump float;
2 | varying vec2 vTextureCo;
3 | uniform sampler2D uTexture;
4 | uniform mat3 uFaltung;
5 | uniform float uWidth;
6 | uniform float uHeight;
7 |
8 |
9 | vec4 getColor(float x,float y,float p){
10 | return p*texture2D(uTexture,vec2(x/uWidth,y/uHeight)+vTextureCo);
11 | }
12 |
13 | void main() {
14 |
15 | vec4 color;
16 |
17 | color+=getColor(-1.,-1.,uFaltung[0][0]);
18 | color+=getColor(0.,-1.,uFaltung[1][0]);
19 | color+=getColor(1.,-1.,uFaltung[2][0]);
20 |
21 | color+=getColor(-1.,0.,uFaltung[0][1]);
22 | color+=getColor(0.,0.,uFaltung[1][1]);
23 | color+=getColor(1.,0.,uFaltung[2][1]);
24 |
25 | color+=getColor(-1.,1.,uFaltung[0][2]);
26 | color+=getColor(0.,1.,uFaltung[1][2]);
27 | color+=getColor(1.,1.,uFaltung[2][2]);
28 |
29 | gl_FragColor = color;
30 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/func/gauss.frag:
--------------------------------------------------------------------------------
1 | precision mediump float;
2 | varying vec2 vTextureCo;
3 | uniform sampler2D uTexture;
4 | uniform float uWidth;
5 | uniform float uHeight;
6 |
7 |
8 | vec4 getColor(float x,float y,float p){
9 | return p*texture2D(uTexture,vec2(x/uWidth,y/uHeight)+vTextureCo);
10 | }
11 |
12 | void main() {
13 |
14 | vec4 color;
15 |
16 | color+=getColor(-2.,-2.,2.);
17 | color+=getColor(-1.,-2.,4.);
18 | color+=getColor(0.,-2.,5.);
19 | color+=getColor(1.,-2.,4.);
20 | color+=getColor(2.,-2.,2.);
21 |
22 | color+=getColor(-2.,-1.,4.);
23 | color+=getColor(-1.,-1.,9.);
24 | color+=getColor(0.,-1.,12.);
25 | color+=getColor(1.,-1.,9.);
26 | color+=getColor(2.,-1.,4.);
27 |
28 | color+=getColor(-2.,1.,4.);
29 | color+=getColor(-1.,1.,9.);
30 | color+=getColor(0.,1.,12.);
31 | color+=getColor(1.,1.,9.);
32 | color+=getColor(2.,1.,4.);
33 |
34 | color+=getColor(-2.,0.,9.);
35 | color+=getColor(-1.,0.,12.);
36 | color+=getColor(0.,0.,15.);
37 | color+=getColor(1.,0.,12.);
38 | color+=getColor(2.,0.,9.);
39 |
40 | color+=getColor(-2.,2.,2.);
41 | color+=getColor(-1.,2.,4.);
42 | color+=getColor(0.,2.,5.);
43 | color+=getColor(1.,2.,4.);
44 | color+=getColor(2.,2.,2.);
45 |
46 | gl_FragColor = color/159.;
47 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/func/sobel.frag:
--------------------------------------------------------------------------------
1 | precision highp float;
2 |
3 | uniform sampler2D uTexture;
4 | uniform float uWidth;
5 | uniform float uHeight;
6 | varying vec2 vTextureCo;
7 | const float step=1.;
8 | const mat3 GX=mat3(-1.,0., +1., -2., 0., +2., -1., 0., +1.);
9 | const mat3 GY=mat3(-1., -2., -1., 0., 0., 0., +1., +2., +1.);
10 |
11 | //sobel 算子有两个滤波矩阵Gx和Gy,注意:
12 | //边缘检测时Gx为检测纵向边缘,Gy为检测横向边缘
13 | //计算法线时Gx为计算法线的横向偏移,Gy为计算法线的纵向偏移
14 | //Gx为[-1 0 +1 -2 0 +2 -1 0 +1] 3*3矩阵
15 | //Gy为[-1 -2 -1 0 0 0 +1 +2 +1] 3*3矩阵
16 |
17 | float colorR(vec2 center,float shiftX,float shiftY){
18 | return texture2D(uTexture,vec2(vTextureCo.x+shiftX/uWidth,vTextureCo.y+shiftY/uHeight)).r;
19 | }
20 |
21 | void main(){
22 | vec2 center=vec2(vTextureCo.x*uWidth,vTextureCo.y*uHeight);
23 | float leftTop=colorR(center,-step,-step);
24 | float centerTop=colorR(center,0.,-step);
25 | float rightTop=colorR(center,step,-step);
26 | float leftCenter=colorR(center,-step,0.);
27 | float rightCenter=colorR(center,step,0.);
28 | float leftBottom=colorR(center,-step,step);
29 | float centerBottom=colorR(center,0.,step);
30 | float rightBottom=colorR(center,step,step);
31 | mat3 d=mat3(colorR(center,-step,-step),colorR(center,0.,-step),colorR(center,step,-step),
32 | colorR(center,-step,0.),colorR(center,0.,0.),colorR(center,step,0.),
33 | colorR(center,-step,step),colorR(center,0.,step),colorR(center,step,step));
34 | float x = d[0][0]*GX[0][0]+d[1][0]*GX[1][0]+d[2][0]*GX[2][0]+
35 | d[0][1]*GX[0][1]+d[1][1]*GX[1][1]+d[2][1]*GX[2][1]+
36 | d[0][2]*GX[0][2]+d[1][2]*GX[1][2]+d[2][2]*GX[2][2];
37 | float y = d[0][0]*GY[0][0]+d[1][0]*GY[1][0]+d[2][0]*GY[2][0]+
38 | d[0][1]*GY[0][1]+d[1][1]*GY[1][1]+d[2][1]*GY[2][1]+
39 | d[0][2]*GY[0][2]+d[1][2]*GY[1][2]+d[2][2]*GY[2][2];
40 | gl_FragColor=vec4(vec3(length(vec2(x,y))),1.);
41 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/func/sobel2.frag:
--------------------------------------------------------------------------------
1 | precision highp float;
2 |
3 | uniform sampler2D uTexture;
4 | uniform float uWidth;
5 | uniform float uHeight;
6 | varying vec2 vTextureCo;
7 | const float step=1.;
8 | const mat3 GX=mat3(-1.,0., +1., -1., 0., +1., -1., 0., +1.);
9 | const mat3 GY=mat3(-1., -1., -1., 0., 0., 0., +1., +1., +1.);
10 |
11 | //sobel 算子有两个滤波矩阵Gx和Gy,注意:
12 | //边缘检测时Gx为检测纵向边缘,Gy为检测横向边缘
13 | //计算法线时Gx为计算法线的横向偏移,Gy为计算法线的纵向偏移
14 | //Gx为[-1 0 +1 -2 0 +2 -1 0 +1] 3*3矩阵
15 | //Gy为[-1 -2 -1 0 0 0 +1 +2 +1] 3*3矩阵
16 |
17 | float colorR(vec2 center,float shiftX,float shiftY){
18 | return texture2D(uTexture,vec2(vTextureCo.x+shiftX/uWidth,vTextureCo.y+shiftY/uHeight)).r;
19 | }
20 |
21 | void main(){
22 | vec2 center=vec2(vTextureCo.x*uWidth,vTextureCo.y*uHeight);
23 | float leftTop=colorR(center,-step,-step);
24 | float centerTop=colorR(center,0.,-step);
25 | float rightTop=colorR(center,step,-step);
26 | float leftCenter=colorR(center,-step,0.);
27 | float rightCenter=colorR(center,step,0.);
28 | float leftBottom=colorR(center,-step,step);
29 | float centerBottom=colorR(center,0.,step);
30 | float rightBottom=colorR(center,step,step);
31 | mat3 d=mat3(colorR(center,-step,-step),colorR(center,0.,-step),colorR(center,step,-step),
32 | colorR(center,-step,0.),colorR(center,0.,0.),colorR(center,step,0.),
33 | colorR(center,-step,step),colorR(center,0.,step),colorR(center,step,step));
34 | float x = d[0][0]*GX[0][0]+d[1][0]*GX[1][0]+d[2][0]*GX[2][0]+
35 | d[0][1]*GX[0][1]+d[1][1]*GX[1][1]+d[2][1]*GX[2][1]+
36 | d[0][2]*GX[0][2]+d[1][2]*GX[1][2]+d[2][2]*GX[2][2];
37 | float y = d[0][0]*GY[0][0]+d[1][0]*GY[1][0]+d[2][0]*GY[2][0]+
38 | d[0][1]*GY[0][1]+d[1][1]*GY[1][1]+d[2][1]*GY[2][1]+
39 | d[0][2]*GY[0][2]+d[1][2]*GY[1][2]+d[2][2]*GY[2][2];
40 | gl_FragColor=vec4(vec3(1.)-vec3(length(vec2(x,y))),1.);
41 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/oes.frag:
--------------------------------------------------------------------------------
1 | #extension GL_OES_EGL_image_external : require
2 | precision mediump float;
3 | varying vec2 vTextureCo;
4 | uniform samplerExternalOES uTexture;
5 | void main() {
6 | gl_FragColor = texture2D( uTexture, vTextureCo);
7 | }
--------------------------------------------------------------------------------
/aavt/src/main/assets/shader/oes.vert:
--------------------------------------------------------------------------------
1 | attribute vec4 aVertexCo;
2 | attribute vec2 aTextureCo;
3 |
4 | uniform mat4 uVertexMatrix;
5 | uniform mat4 uTextureMatrix;
6 |
7 | varying vec2 vTextureCo;
8 |
9 | void main(){
10 | gl_Position = uVertexMatrix*aVertexCo;
11 | vTextureCo = (uTextureMatrix*vec4(aTextureCo,0,1)).xy;
12 | }
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/av/CameraRecorder2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.av;
15 |
16 | import android.content.Context;
17 |
18 | import com.wuwang.aavt.core.Renderer;
19 | import com.wuwang.aavt.media.video.Camera2Provider;
20 | import com.wuwang.aavt.media.video.ITextureProvider;
21 | import com.wuwang.aavt.media.SurfaceEncoder;
22 | import com.wuwang.aavt.media.SoundRecorder;
23 | import com.wuwang.aavt.media.SurfaceShower;
24 | import com.wuwang.aavt.media.VideoSurfaceProcessor;
25 | import com.wuwang.aavt.media.av.AvException;
26 | import com.wuwang.aavt.media.hard.IHardStore;
27 | import com.wuwang.aavt.media.hard.StrengthenMp4MuxStore;
28 |
29 | /**
30 | * CameraRecorder2 相机预览及录制工具类
31 | *
32 | * @author wuwang
33 | * @version v1.0 2017:10:26 18:35
34 | */
35 | public class CameraRecorder2 {
36 |
37 | private VideoSurfaceProcessor mTextureProcessor;
38 | private ITextureProvider mCameraProvider;
39 | private SurfaceShower mShower;
40 | private SurfaceEncoder mSurfaceStore;
41 | private IHardStore mMuxer;
42 |
43 | private SoundRecorder mSoundRecord;
44 |
45 | public CameraRecorder2(Context context){
46 | //用于视频混流和存储
47 | mMuxer=new StrengthenMp4MuxStore(true);
48 |
49 | //用于预览图像
50 | mShower=new SurfaceShower();
51 | mShower.setOutputSize(720,1280);
52 |
53 | //用于编码图像
54 | mSurfaceStore=new SurfaceEncoder();
55 | mSurfaceStore.setStore(mMuxer);
56 |
57 | //用于音频
58 | mSoundRecord=new SoundRecorder(mMuxer);
59 |
60 | //用于处理视频图像
61 | mTextureProcessor=new VideoSurfaceProcessor();
62 | mTextureProcessor.setTextureProvider(mCameraProvider=new Camera2Provider(context));
63 | mTextureProcessor.addObserver(mShower);
64 | mTextureProcessor.addObserver(mSurfaceStore);
65 | }
66 |
67 | public void setRenderer(Renderer renderer){
68 | mTextureProcessor.setRenderer(renderer);
69 | }
70 |
71 | /**
72 | * 设置预览对象,必须是{@link android.view.Surface}、{@link android.graphics.SurfaceTexture}或者
73 | * {@link android.view.TextureView}
74 | * @param surface 预览对象
75 | */
76 | public void setSurface(Object surface){
77 | mShower.setSurface(surface);
78 | }
79 |
80 | /**
81 | * 设置录制的输出路径
82 | * @param path 输出路径
83 | */
84 | public void setOutputPath(String path){
85 | mMuxer.setOutputPath(path);
86 | }
87 |
88 | /**
89 | * 设置预览大小
90 | * @param width 预览区域宽度
91 | * @param height 预览区域高度
92 | */
93 | public void setPreviewSize(int width,int height){
94 | mShower.setOutputSize(width,height);
95 | }
96 |
97 | /**
98 | * 打开数据源
99 | */
100 | public void open(){
101 | mTextureProcessor.start();
102 | }
103 |
104 | /**
105 | * 关闭数据源
106 | */
107 | public void close(){
108 | mTextureProcessor.stop();
109 | stopRecord();
110 | }
111 |
112 | /**
113 | * 打开预览
114 | */
115 | public void startPreview(){
116 | mShower.open();
117 | }
118 |
119 | /**
120 | * 关闭预览
121 | */
122 | public void stopPreview(){
123 | mShower.close();
124 | }
125 |
126 | /**
127 | * 开始录制
128 | */
129 | public void startRecord(){
130 | mSurfaceStore.open();
131 | mSoundRecord.start();
132 | }
133 |
134 | /**
135 | * 关闭录制
136 | */
137 | public void stopRecord(){
138 | mSoundRecord.stop();
139 | mSurfaceStore.close();
140 | mMuxer.close();
141 | }
142 |
143 | }
144 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/av/Mp4Processor2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.av;
15 |
16 | import com.wuwang.aavt.media.video.Mp4Provider;
17 | import com.wuwang.aavt.media.SurfaceEncoder;
18 | import com.wuwang.aavt.media.SurfaceShower;
19 | import com.wuwang.aavt.media.VideoSurfaceProcessor;
20 | import com.wuwang.aavt.media.hard.IHardStore;
21 | import com.wuwang.aavt.media.hard.StrengthenMp4MuxStore;
22 |
23 | /**
24 | * Mp4Processor2 用于处理Mp4文件
25 | *
26 | * @author wuwang
27 | * @version v1.0 2017:10:26 18:48
28 | */
29 | public class Mp4Processor2 {
30 |
31 | private VideoSurfaceProcessor mTextureProcessor;
32 | private Mp4Provider mMp4Provider;
33 | private SurfaceShower mShower;
34 | private SurfaceEncoder mSurfaceStore;
35 | private IHardStore mMuxer;
36 |
37 | public Mp4Processor2(){
38 | //用于视频混流和存储
39 | mMuxer=new StrengthenMp4MuxStore(true);
40 |
41 | //用于预览图像
42 | mShower=new SurfaceShower();
43 | mShower.setOutputSize(720,1280);
44 |
45 | //用于编码图像
46 | mSurfaceStore=new SurfaceEncoder();
47 | mSurfaceStore.setStore(mMuxer);
48 |
49 | //用于音频
50 | // mSoundRecord=new SoundRecorder(mMuxer);
51 | mMp4Provider=new Mp4Provider();
52 | mMp4Provider.setStore(mMuxer);
53 |
54 | //用于处理视频图像
55 | mTextureProcessor=new VideoSurfaceProcessor();
56 | mTextureProcessor.setTextureProvider(mMp4Provider);
57 | mTextureProcessor.addObserver(mShower);
58 | mTextureProcessor.addObserver(mSurfaceStore);
59 | }
60 |
61 | public void setSurface(Object surface){
62 | mShower.setSurface(surface);
63 | }
64 |
65 | public void setInputPath(String path){
66 | mMp4Provider.setInputPath(path);
67 | }
68 |
69 | public void setOutputPath(String path){
70 | mMuxer.setOutputPath(path);
71 | }
72 |
73 | public void setPreviewSize(int width,int height){
74 | mShower.setOutputSize(width,height);
75 | }
76 |
77 | public void open(){
78 | mTextureProcessor.start();
79 | }
80 |
81 | public void close(){
82 | mTextureProcessor.stop();
83 | }
84 |
85 | public void startPreview(){
86 | mShower.open();
87 | }
88 |
89 | public void stopPreview(){
90 | mShower.close();
91 | }
92 |
93 | public void startRecord(){
94 | mSurfaceStore.open();
95 | // mSoundRecord.start();
96 | }
97 |
98 | public void stopRecord(){
99 | mSurfaceStore.close();
100 | // mSoundRecord.stop();
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/av/SurfaceRecorder.java:
--------------------------------------------------------------------------------
1 | package com.wuwang.aavt.av;
2 |
3 | import android.content.Context;
4 |
5 | import com.wuwang.aavt.core.Renderer;
6 | import com.wuwang.aavt.media.video.Camera2Provider;
7 | import com.wuwang.aavt.media.video.ITextureProvider;
8 | import com.wuwang.aavt.media.SoundRecorder;
9 | import com.wuwang.aavt.media.SurfaceEncoder;
10 | import com.wuwang.aavt.media.SurfaceShower;
11 | import com.wuwang.aavt.media.VideoSurfaceProcessor;
12 | import com.wuwang.aavt.media.av.AvException;
13 | import com.wuwang.aavt.media.hard.IHardStore;
14 | import com.wuwang.aavt.media.hard.StrengthenMp4MuxStore;
15 |
16 | /**
17 | * @author wuwang
18 | * @version 1.00 , 2018/11/14
19 | */
20 | public class SurfaceRecorder {
21 |
22 | private Context context;
23 | private VideoSurfaceProcessor mTextureProcessor;
24 | private SurfaceShower mShower;
25 | private SurfaceEncoder mSurfaceStore;
26 | private IHardStore mMuxer;
27 |
28 | private ITextureProvider mProvider;
29 | private SoundRecorder mSoundRecord;
30 |
31 | private int mPreviewWidth = 720;
32 | private int mPreviewHeight = 1280;
33 | private int mRecordWidth = 720;
34 | private int mRecordHeight = 1280;
35 | private String path;
36 | private Renderer mRender;
37 | private Object mShowSurface;
38 |
39 | public SurfaceRecorder(Context context){
40 | this.context = context;
41 | }
42 |
43 | public void setTextureProvider(ITextureProvider provider){
44 | this.mProvider = provider;
45 | }
46 |
47 | public void setPreviewSize(int width,int height){
48 | this.mPreviewWidth = width;
49 | this.mPreviewHeight = height;
50 | }
51 |
52 | public void setRecordSize(int width,int height){
53 | this.mRecordWidth = width;
54 | this.mRecordHeight = height;
55 | }
56 |
57 | public void setSurface(Object surface){
58 | this.mShowSurface = surface;
59 | }
60 |
61 | /**
62 | * 设置录制的输出路径
63 | * @param path 输出路径
64 | */
65 | public void setOutputPath(String path){
66 | this.path = path;
67 | }
68 |
69 | public void setRenderer(Renderer renderer){
70 | this.mRender = renderer;
71 | }
72 |
73 | public void open(){
74 | if(mMuxer == null){
75 | mMuxer=new StrengthenMp4MuxStore(true);
76 | mMuxer.setOutputPath(path);
77 | }
78 |
79 | if(mProvider == null){
80 | mProvider=new Camera2Provider(context);
81 | }
82 |
83 | if(mShower == null){
84 | //用于预览图像
85 | mShower=new SurfaceShower();
86 | mShower.setOutputSize(mPreviewWidth,mPreviewHeight);
87 | mShower.setSurface(mShowSurface);
88 | }
89 |
90 | if(mSurfaceStore == null){
91 | //用于编码图像
92 | mSurfaceStore=new SurfaceEncoder();
93 | mSurfaceStore.setOutputSize(mRecordWidth,mRecordHeight);
94 | mSurfaceStore.setStore(mMuxer);
95 | }
96 |
97 | if(mSoundRecord == null){
98 | //用于音频
99 | mSoundRecord=new SoundRecorder(mMuxer);
100 | }
101 |
102 | if(mTextureProcessor == null){
103 | //用于处理视频图像
104 | mTextureProcessor=new VideoSurfaceProcessor();
105 | mTextureProcessor.setTextureProvider(mProvider);
106 | mTextureProcessor.addObserver(mShower);
107 | mTextureProcessor.addObserver(mSurfaceStore);
108 | mTextureProcessor.setRenderer(mRender);
109 | }
110 | mTextureProcessor.start();
111 | }
112 |
113 | public void close(){
114 | if(mTextureProcessor != null){
115 | mTextureProcessor.stop();
116 | }
117 | }
118 |
119 | public void startPreview(){
120 | if(mShower != null){
121 | mShower.open();
122 | }
123 | }
124 |
125 | public void stopPreview(){
126 | if(mShower != null){
127 | mShower.close();
128 | }
129 | }
130 |
131 | /**
132 | * 开始录制
133 | */
134 | public void startRecord(){
135 | if(mSurfaceStore != null && mSoundRecord !=null){
136 | mSurfaceStore.open();
137 | mSoundRecord.start();
138 | }
139 | }
140 |
141 | /**
142 | * 关闭录制
143 | */
144 | public void stopRecord(){
145 | if(mSoundRecord != null && mSurfaceStore != null && mMuxer != null){
146 | mSoundRecord.stop();
147 | mSurfaceStore.close();
148 | mMuxer.close();
149 | }
150 | }
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/av/VideoCapture.java:
--------------------------------------------------------------------------------
1 | package com.wuwang.aavt.av;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.util.SparseArray;
6 |
7 | import com.wuwang.aavt.core.Renderer;
8 | import com.wuwang.aavt.media.video.CameraProvider;
9 | import com.wuwang.aavt.media.video.ITextureProvider;
10 | import com.wuwang.aavt.media.video.Mp4Provider;
11 | import com.wuwang.aavt.media.SurfaceEncoder;
12 | import com.wuwang.aavt.media.SurfaceShower;
13 | import com.wuwang.aavt.media.VideoSurfaceProcessor;
14 | import com.wuwang.aavt.media.hard.IHardStore;
15 | import com.wuwang.aavt.media.hard.StrengthenMp4MuxStore;
16 |
17 | /**
18 | * @author wuwang
19 | * @version 1.00 , 2019/03/13
20 | */
21 | public class VideoCapture {
22 |
23 | public static final int KEY_CAMERA_MIN_WIDTH = 1;
24 | public static final int KEY_CAMERA_RATE = 2;
25 | public static final int KEY_OUTPUT_WIDTH = 3;
26 | public static final int KEY_OUTPUT_HEIGHT = 4;
27 | public static final int KEY_OUTPUT_PATH = 5;
28 | public static final int KEY_PREVIEW_WIDTH = 6;
29 | public static final int KEY_PREVIEW_HEIGHT = 7;
30 |
31 | private Context context;
32 | private ITextureProvider provider;
33 | private SurfaceShower shower;
34 | private SurfaceEncoder encoder;
35 | private VideoSurfaceProcessor processor;
36 | private IHardStore muxer;
37 | private SparseArray propFloat;
38 | private SparseArray propStr;
39 | private Renderer renderer;
40 | private Object showSurface;
41 |
42 | @SuppressLint("SdCardPath")
43 | private static final String DEFAULT_OUTPUT_PATH = "/mnt/sdcard/test.mp4";
44 |
45 | public VideoCapture(Context context){
46 | this.context = context;
47 | propFloat = new SparseArray<>();
48 | propStr = new SparseArray<>();
49 | }
50 |
51 | public void setRenderer(Renderer renderer){
52 | this.renderer = renderer;
53 | if(processor != null){
54 | processor.setRenderer(renderer);
55 | }
56 | }
57 |
58 | public void setProperty(int key,float value){
59 | propFloat.put(key,value);
60 | }
61 |
62 | public void setProperty(int key,String value){
63 | propStr.put(key,value);
64 | }
65 |
66 | @SuppressLint("SdCardPath")
67 | public void open(int id){
68 | provider = new CameraProvider();
69 | ((CameraProvider) provider).setDefaultCamera(id);
70 | ((CameraProvider) provider).setCameraSize((int)(float)(propFloat.get(KEY_CAMERA_MIN_WIDTH,720f)),propFloat.get(KEY_CAMERA_RATE,1.7f));
71 |
72 | shower = new SurfaceShower();
73 | shower.setOutputSize((int)(float)(propFloat.get(KEY_PREVIEW_WIDTH,720.0f)),
74 | (int)(float)(propFloat.get(KEY_PREVIEW_HEIGHT,1280.0f)));
75 |
76 | muxer = new StrengthenMp4MuxStore(false);
77 | muxer.setOutputPath(propStr.get(KEY_OUTPUT_PATH,DEFAULT_OUTPUT_PATH));
78 |
79 | encoder = new SurfaceEncoder();
80 | encoder.setStore(muxer);
81 | encoder.setOutputSize((int)(float)(propFloat.get(KEY_OUTPUT_WIDTH,368.0f)),
82 | (int)(float)(propFloat.get(KEY_OUTPUT_HEIGHT,640.f)));
83 |
84 | processor = new VideoSurfaceProcessor();
85 | processor.setTextureProvider(provider);
86 | processor.addObserver(shower);
87 | processor.addObserver(encoder);
88 | setRenderer(renderer);
89 |
90 | processor.start();
91 | }
92 |
93 | public void open(String path){
94 | muxer = new StrengthenMp4MuxStore(false);
95 | muxer.setOutputPath(propStr.get(KEY_OUTPUT_PATH,DEFAULT_OUTPUT_PATH));
96 |
97 | provider = new Mp4Provider();
98 | ((Mp4Provider) provider).setInputPath(path);
99 | ((Mp4Provider) provider).setStore(muxer);
100 |
101 | shower = new SurfaceShower();
102 | shower.setOutputSize((int)(float)(propFloat.get(KEY_OUTPUT_WIDTH,720.0f)),
103 | (int)(float)(propFloat.get(KEY_OUTPUT_HEIGHT,1280.0f)));
104 |
105 | encoder = new SurfaceEncoder();
106 | encoder.setStore(muxer);
107 | encoder.setOutputSize((int)(float)(propFloat.get(KEY_OUTPUT_WIDTH,368.0f)),
108 | (int)(float)(propFloat.get(KEY_OUTPUT_HEIGHT,640.f)));
109 |
110 | processor = new VideoSurfaceProcessor();
111 | processor.setTextureProvider(provider);
112 | processor.addObserver(shower);
113 | processor.addObserver(encoder);
114 | setRenderer(renderer);
115 |
116 | processor.start();
117 | }
118 |
119 | public void setPreviewSurface(Object surface){
120 | this.showSurface = surface;
121 | if(shower != null){
122 | shower.setSurface(surface);
123 | }
124 | }
125 |
126 | public void startPreview(){
127 | setPreviewSurface(showSurface);
128 | shower.open();
129 | }
130 |
131 | public void stopPreview(){
132 | shower.close();
133 | }
134 |
135 | public void startRecord(){
136 | encoder.open();
137 | }
138 |
139 | public void stopRecord(){
140 | encoder.close();
141 | muxer.close();
142 | }
143 |
144 |
145 | public void close(){
146 | processor.stop();
147 | }
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/core/IObservable.java:
--------------------------------------------------------------------------------
1 | package com.wuwang.aavt.core;
2 |
3 | /**
4 | * Created by wuwang on 2017/10/20.
5 | */
6 |
7 | public interface IObservable {
8 |
9 | void addObserver(IObserver observer);
10 |
11 | void notify(Type type);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/core/IObserver.java:
--------------------------------------------------------------------------------
1 | package com.wuwang.aavt.core;
2 |
3 | /**
4 | * Created by wuwang on 2017/10/20.
5 | */
6 |
7 | public interface IObserver {
8 |
9 | void onCall(Type type);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/core/Observable.java:
--------------------------------------------------------------------------------
1 | package com.wuwang.aavt.core;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Observer;
5 |
6 | /*
7 | * Created by Wuwang on 2017/10/23
8 | */
9 | public class Observable implements IObservable {
10 |
11 | private ArrayList> temp;
12 |
13 | @Override
14 | public void addObserver(IObserver observer) {
15 | if(temp==null){
16 | temp=new ArrayList<>();
17 | }
18 | temp.add(observer);
19 | }
20 |
21 | public void clear(){
22 | if(temp!=null){
23 | temp.clear();
24 | temp=null;
25 | }
26 | }
27 |
28 | @Override
29 | public void notify(Type type) {
30 | for (IObserver t:temp){
31 | t.onCall(type);
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/core/Renderer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.core;
15 |
16 | /**
17 | * Renderer 渲染接口,渲染的四个接口应该在同一个GL线程中调用
18 | *
19 | * @author wuwang
20 | * @version v1.0 2017:10:31 11:40
21 | */
22 | public interface Renderer {
23 |
24 | /**
25 | * 创建
26 | */
27 | void create();
28 |
29 | /**
30 | * 大小改变
31 | * @param width 宽度
32 | * @param height 高度
33 | */
34 | void sizeChanged(int width, int height);
35 |
36 | /**
37 | * 渲染
38 | * @param texture 输入纹理
39 | */
40 | void draw(int texture);
41 |
42 | /**
43 | * 销毁
44 | */
45 | void destroy();
46 |
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/egl/EGLConfigAttrs.java:
--------------------------------------------------------------------------------
1 | package com.wuwang.aavt.egl;
2 |
3 | import android.opengl.EGL14;
4 |
5 | import java.util.Arrays;
6 |
7 | import javax.microedition.khronos.egl.EGL10;
8 |
9 | /*
10 | * Created by Wuwang on 2017/10/18
11 | */
12 | public class EGLConfigAttrs {
13 |
14 | private int red=8;
15 | private int green=8;
16 | private int blue=8;
17 | private int alpha=8;
18 | private int depth=8;
19 | private int renderType=4;
20 | private int surfaceType= EGL10.EGL_WINDOW_BIT;
21 |
22 | private boolean makeDefault=false;
23 |
24 | public EGLConfigAttrs red(int red){
25 | this.red=red;
26 | return this;
27 | }
28 |
29 | public EGLConfigAttrs green(int green){
30 | this.green=green;
31 | return this;
32 | }
33 |
34 | public EGLConfigAttrs blue(int blue){
35 | this.blue=blue;
36 | return this;
37 | }
38 |
39 | public EGLConfigAttrs alpha(int alpha){
40 | this.alpha=alpha;
41 | return this;
42 | }
43 |
44 | public EGLConfigAttrs depth(int depth){
45 | this.depth=depth;
46 | return this;
47 | }
48 |
49 | public EGLConfigAttrs renderType(int type){
50 | this.renderType=type;
51 | return this;
52 | }
53 |
54 | public EGLConfigAttrs surfaceType(int type){
55 | this.surfaceType=type;
56 | return this;
57 | }
58 |
59 | public EGLConfigAttrs makeDefault(boolean def){
60 | this.makeDefault=def;
61 | return this;
62 | }
63 |
64 | public boolean isDefault(){
65 | return makeDefault;
66 | }
67 |
68 | int[] build(){
69 | return new int[] {
70 | EGL10.EGL_SURFACE_TYPE, surfaceType, //渲染类型
71 | EGL10.EGL_RED_SIZE, red, //指定RGB中的R大小(bits)
72 | EGL10.EGL_GREEN_SIZE, green, //指定G大小
73 | EGL10.EGL_BLUE_SIZE, blue, //指定B大小
74 | EGL10.EGL_ALPHA_SIZE, alpha, //指定Alpha大小,以上四项实际上指定了像素格式
75 | EGL10.EGL_DEPTH_SIZE, depth, //指定深度缓存(Z Buffer)大小
76 | EGL10.EGL_RENDERABLE_TYPE, renderType, //指定渲染api类别, 如上一小节描述,这里或者是硬编码的4(EGL14.EGL_OPENGL_ES2_BIT)
77 | EGL10.EGL_NONE }; //总是以EGL14.EGL_NONE结尾
78 | }
79 |
80 | @Override
81 | public String toString() {
82 | return Arrays.toString(build());
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/egl/EGLContextAttrs.java:
--------------------------------------------------------------------------------
1 | package com.wuwang.aavt.egl;
2 |
3 | import javax.microedition.khronos.egl.EGL10;
4 |
5 | /*
6 | * Created by Wuwang on 2017/10/18
7 | */
8 | public class EGLContextAttrs {
9 |
10 | private int version=2;
11 |
12 | private boolean isDefault;
13 |
14 | public EGLContextAttrs version(int v){
15 | this.version=v;
16 | return this;
17 | }
18 |
19 | public EGLContextAttrs makeDefault(boolean def){
20 | this.isDefault=def;
21 | return this;
22 | }
23 |
24 | public boolean isDefault(){
25 | return isDefault;
26 | }
27 |
28 | int[] build(){
29 | return new int[]{0x3098,version, EGL10.EGL_NONE};
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/expend/SluggardFilterTool.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.expend;
15 |
16 | import com.wuwang.aavt.gl.BaseFilter;
17 | import java.util.HashMap;
18 | import java.util.Map;
19 |
20 | /**
21 | * SluggardFilterTool 懒汉Filter工具,该工具用于快速使用{@link BaseFilter}及其子类来处理纹理,而无需关注框架中
22 | * 的滤镜处理流程。通常情况下,不推荐使用此工具类,推荐尽可能熟悉框架中的滤镜处理流程。然后自行根据业务逻辑,
23 | * 参照此类进行封装。
24 | *
25 | * @author wuwang
26 | * @version v1.0 2017:11:11 15:41
27 | */
28 | public class SluggardFilterTool {
29 |
30 | private long threadId=-1;
31 | private HashMap filters=new HashMap<>();
32 |
33 | /**
34 | * 处理一个纹理,并输出处理后的纹理
35 | * @param texture 输入纹理
36 | * @param width 输出纹理宽度
37 | * @param height 输出纹理高度
38 | * @param clazz 滤镜类型
39 | * @return 输出纹理
40 | */
41 | public int processTexture(int texture, int width, int height, Class extends BaseFilter> clazz){
42 | long nowThreadId=Thread.currentThread().getId();
43 | if(nowThreadId!=threadId){
44 | filters.clear();
45 | threadId=nowThreadId;
46 | }
47 | BaseFilter filter=filters.get(clazz);
48 | if(filter==null){
49 | try {
50 | filter=clazz.newInstance();
51 | filter.create();
52 | } catch (InstantiationException e) {
53 | e.printStackTrace();
54 | } catch (IllegalAccessException e) {
55 | e.printStackTrace();
56 | }
57 | filters.put(clazz,filter);
58 | }
59 | if(filter!=null){
60 | filter.sizeChanged(width, height);
61 | return filter.drawToTexture(texture);
62 | }
63 | return -1;
64 | }
65 |
66 | /**
67 | * 处理一个纹理,并输出处理后的纹理
68 | * @param texture 输入纹理
69 | * @param width 输出纹理宽度
70 | * @param height 输出纹理高度
71 | * @param filter 滤镜实体
72 | * @return 输出纹理
73 | */
74 | public int processTexture(int texture,int width,int height,BaseFilter filter){
75 | long nowThreadId=Thread.currentThread().getId();
76 | if(nowThreadId!=threadId){
77 | filters.clear();
78 | threadId=nowThreadId;
79 | }
80 | if(filter!=null){
81 | Class clazz=filter.getClass();
82 | if(filters.get(clazz)==null){
83 | filters.put(clazz,filter);
84 | filter.create();
85 | }
86 | filter.sizeChanged(width, height);
87 | return filter.drawToTexture(texture);
88 | }
89 | return -1;
90 | }
91 |
92 | public void onGlDestroy(){
93 | for (Map.Entry classBaseFilterEntry : filters.entrySet()) {
94 | BaseFilter filter = classBaseFilterEntry.getValue();
95 | filter.destroy();
96 | }
97 | filters.clear();
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/gl/BaseFuncFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.gl;
15 |
16 | import android.content.res.Resources;
17 |
18 | /**
19 | * BaseFuncFilter 基础功能滤镜
20 | *
21 | * @author wuwang
22 | * @version v1.0 2017:10:31 11:47
23 | */
24 | class BaseFuncFilter extends BaseFilter {
25 |
26 | static final String FILTER_SOBEL="shader/func/sobel.frag";
27 | static final String FILTER_SOBEL_REVERSE="shader/func/sobel2.frag";
28 | static final String FILTER_GAUSS="shader/func/gauss.frag";
29 |
30 | BaseFuncFilter(Resources resource, String fragment) {
31 | super(resource, "shader/base.vert", fragment);
32 | shaderNeedTextureSize(true);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/gl/BeautyFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.gl;
15 |
16 | import android.content.res.Resources;
17 | import android.opengl.GLES20;
18 |
19 | /**
20 | * BeautyFilter 美颜滤镜
21 | *
22 | * @author wuwang
23 | * @version v1.0 2017:10:31 11:46
24 | */
25 | public class BeautyFilter extends BaseFilter {
26 |
27 | private int mGLaaCoef;
28 | private int mGLmixCoef;
29 | private int mGLiternum;
30 |
31 |
32 | private float aaCoef;
33 | private float mixCoef;
34 | private int iternum;
35 |
36 | public BeautyFilter(Resources resource) {
37 | super(resource,"shader/beauty/beauty.vert", "shader/beauty/beauty.frag");
38 | shaderNeedTextureSize(true);
39 | setBeautyLevel(0);
40 | }
41 |
42 | @Override
43 | protected void onCreate() {
44 | super.onCreate();
45 | mGLaaCoef= GLES20.glGetUniformLocation(mGLProgram,"uACoef");
46 | mGLmixCoef=GLES20.glGetUniformLocation(mGLProgram,"uMixCoef");
47 | mGLiternum=GLES20.glGetUniformLocation(mGLProgram,"uIternum");
48 | }
49 |
50 | public BaseFilter setBeautyLevel(int level){
51 | switch (level){
52 | case 1:
53 | a(1,0.19f,0.54f);
54 | break;
55 | case 2:
56 | a(2,0.29f,0.54f);
57 | break;
58 | case 3:
59 | a(3,0.17f,0.39f);
60 | break;
61 | case 4:
62 | a(3,0.25f,0.54f);
63 | break;
64 | case 5:
65 | a(4,0.13f,0.54f);
66 | break;
67 | case 6:
68 | a(4,0.19f,0.69f);
69 | break;
70 | default:
71 | a(0,0f,0f);
72 | break;
73 | }
74 | return this;
75 | }
76 |
77 | private void a(final int a, final float b, final float c){
78 | runOnGLThread(new Runnable() {
79 | @Override
80 | public void run() {
81 | GLES20.glUniform1f(mGLaaCoef,b);
82 | GLES20.glUniform1f(mGLmixCoef,c);
83 | GLES20.glUniform1i(mGLiternum,a);
84 | }
85 | });
86 | }
87 |
88 | }
89 |
90 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/gl/BlackMagicFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.gl;
15 |
16 | import android.content.res.Resources;
17 |
18 | /**
19 | * BlackMagicFilter 黑魔法滤镜,sobel算法实现
20 | *
21 | * @author wuwang
22 | * @version v1.0 2017:10:31 11:47
23 | */
24 | public class BlackMagicFilter extends GroupFilter {
25 |
26 | public BlackMagicFilter(Resources resources){
27 | super(resources);
28 | }
29 |
30 | @Override
31 | protected void initBuffer() {
32 | super.initBuffer();
33 | addFilter(new GrayFilter(mRes));
34 | addFilter(new BaseFuncFilter(mRes,BaseFuncFilter.FILTER_SOBEL));
35 | }
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/gl/CandyFilter.java:
--------------------------------------------------------------------------------
1 | package com.wuwang.aavt.gl;
2 |
3 | import android.content.res.Resources;
4 |
5 | /**
6 | * Created by 15581 on 2017/9/30.
7 | */
8 |
9 | public class CandyFilter extends GroupFilter {
10 |
11 | public CandyFilter(Resources resource) {
12 | super(resource);
13 | }
14 |
15 | @Override
16 | protected void initBuffer() {
17 | super.initBuffer();
18 | addFilter(new GrayFilter(mRes));
19 | addFilter(new BaseFuncFilter(mRes,BaseFuncFilter.FILTER_GAUSS));
20 | addFilter(new BaseFuncFilter(mRes,BaseFuncFilter.FILTER_SOBEL));
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/gl/Faltung3x3Filter.java:
--------------------------------------------------------------------------------
1 | package com.wuwang.aavt.gl;
2 |
3 | import android.content.res.Resources;
4 | import android.opengl.GLES20;
5 |
6 | /**
7 | * Created by wuwang on 2017/10/1.
8 | */
9 |
10 | public class Faltung3x3Filter extends BaseFilter {
11 |
12 | private float[] mFaltung;
13 | private int mGLFaltung;
14 |
15 | public static final float[] FILTER_SHARPEN=new float[]{0,-1,0,-1,5,-1,0,-1,0};
16 | public static final float[] FILTER_BORDER=new float[]{0,1,0,1,-4,1,0,1,0};
17 | public static final float[] FILTER_CAMEO=new float[]{2,0,2,0,0,0,3,0,-6};
18 |
19 | public Faltung3x3Filter(Resources res,float[] faltung){
20 | super(res,"shader/base.vert","shader/func/faltung3x3.frag");
21 | shaderNeedTextureSize(true);
22 | this.mFaltung=faltung;
23 | }
24 |
25 | @Override
26 | protected void onCreate() {
27 | super.onCreate();
28 | mGLFaltung= GLES20.glGetUniformLocation(mGLProgram,"uFaltung");
29 | }
30 |
31 | @Override
32 | protected void onSetExpandData() {
33 | super.onSetExpandData();
34 | GLES20.glUniformMatrix3fv(mGLFaltung,1,false,mFaltung,0);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/gl/FluorescenceFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.gl;
15 |
16 | import android.content.res.Resources;
17 | import android.opengl.GLES20;
18 |
19 | /**
20 | * FluorescenceFilter 荧光滤镜
21 | *
22 | * @author wuwang
23 | * @version v1.0 2017:10:31 11:50
24 | */
25 | public class FluorescenceFilter extends BaseFilter {
26 |
27 | private int mGLTexture2;
28 | private int mGLBorderColor;
29 | private int mGLStep;
30 | private BlackMagicFilter mBlackFilter;
31 | private int mTempTexture;
32 | private float[] mBorderColor=new float[]{0f,1f,1f,1};
33 | private float mStep=1.0f;
34 |
35 | private boolean isAdd=true;
36 |
37 | public FluorescenceFilter(Resources resource) {
38 | super(resource, "shader/base.vert", "shader/effect/fluorescence.frag");
39 | shaderNeedTextureSize(true);
40 | mBlackFilter=new BlackMagicFilter(resource);
41 | }
42 |
43 | @Override
44 | protected void onCreate() {
45 | mBlackFilter.create();
46 | super.onCreate();
47 | mGLTexture2= GLES20.glGetUniformLocation(mGLProgram,"uTexture2");
48 | mGLBorderColor= GLES20.glGetUniformLocation(mGLProgram,"uBorderColor");
49 | mGLStep=GLES20.glGetUniformLocation(mGLProgram,"uStep");
50 | }
51 |
52 | @Override
53 | protected void onSizeChanged(int width, int height) {
54 | super.onSizeChanged(width, height);
55 | mBlackFilter.sizeChanged(width, height);
56 | }
57 |
58 | @Override
59 | public void draw(int texture) {
60 | mTempTexture=mBlackFilter.drawToTexture(texture);
61 | super.draw(texture);
62 | }
63 |
64 | @Override
65 | protected void onBindTexture(int textureId) {
66 | super.onBindTexture(textureId);
67 | GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
68 | GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,mTempTexture);
69 | GLES20.glUniform1i(mGLTexture2,1);
70 | }
71 |
72 | @Override
73 | protected void onSetExpandData() {
74 | //todo 根据时间修改
75 |
76 | if(isAdd){
77 | mStep+=0.08f;
78 | }else{
79 | mStep-=0.08f;
80 | }
81 |
82 | if(mStep>=1.0f){
83 | isAdd=false;
84 | mStep=1.0f;
85 | }else if(mStep<=0.0f){
86 | isAdd=true;
87 | mStep=0.0f;
88 | }
89 |
90 | super.onSetExpandData();
91 | GLES20.glUniform4fv(mGLBorderColor,1,mBorderColor,0);
92 | GLES20.glUniform1f(mGLStep,mStep);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/gl/GrayFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.gl;
15 |
16 | import android.content.res.Resources;
17 |
18 | /**
19 | * GrayFilter 灰度滤镜
20 | *
21 | * @author wuwang
22 | * @version v1.0 2017:10:31 11:52
23 | */
24 | public class GrayFilter extends BaseFilter {
25 |
26 | public GrayFilter(Resources resource) {
27 | super(resource, "shader/base.vert", "shader/color/gray.frag");
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/gl/GroupFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.gl;
15 |
16 | import android.content.res.Resources;
17 |
18 | import java.util.ArrayList;
19 | import java.util.Iterator;
20 | import java.util.Vector;
21 |
22 | /**
23 | * GroupFilter 滤镜组,将多个滤镜串联起来,合并成一个滤镜
24 | *
25 | * @author wuwang
26 | * @version v1.0 2017:10:31 11:53
27 | */
28 | public class GroupFilter extends LazyFilter {
29 |
30 | private ArrayList mGroup;
31 |
32 | public GroupFilter(Resources resource) {
33 | super(resource);
34 | }
35 |
36 | public GroupFilter(){
37 | super();
38 | }
39 |
40 | @Override
41 | protected void initBuffer() {
42 | super.initBuffer();
43 | mGroup=new ArrayList<>();
44 | }
45 |
46 | public void addFilter(final BaseFilter filter){
47 | runOnGLThread(new Runnable() {
48 | @Override
49 | public void run() {
50 | filter.create();
51 | filter.sizeChanged(mWidth,mHeight);
52 | mGroup.add(filter);
53 | }
54 | });
55 | }
56 |
57 | public void addFilter(final int index,final BaseFilter filter){
58 | runOnGLThread(new Runnable() {
59 | @Override
60 | public void run() {
61 | filter.create();
62 | filter.sizeChanged(mWidth,mHeight);
63 | mGroup.add(index, filter);
64 | }
65 | });
66 | }
67 |
68 | public BaseFilter removeFilter(final int index){
69 | BaseFilter filter=mGroup.get(index);
70 | runOnGLThread(new Runnable() {
71 | @Override
72 | public void run() {
73 | BaseFilter filter=mGroup.remove(index);
74 | if(filter!=null){
75 | filter.destroy();
76 | }
77 | }
78 | });
79 | return filter;
80 | }
81 |
82 | public void removeFilter(final BaseFilter filter){
83 | runOnGLThread(new Runnable() {
84 | @Override
85 | public void run() {
86 | mGroup.remove(filter);
87 | }
88 | });
89 | }
90 |
91 | public BaseFilter get(int index){
92 | return mGroup.get(index);
93 | }
94 |
95 | public Iterator iterator(){
96 | return mGroup.iterator();
97 | }
98 |
99 | public boolean isEmpty(){
100 | return mGroup.isEmpty();
101 | }
102 |
103 | @Override
104 | public void draw(int texture) {
105 | int tempTextureId=texture;
106 | for (int i=0;i=(mXRollTime+mYRollTime)){
54 | mFrameCount=0;
55 | }
56 | if(mFrameCount= Build.VERSION_CODES.LOLLIPOP) {
32 | return codec.getInputBuffer(index);
33 | }else{
34 | return codec.getInputBuffers()[index];
35 | }
36 | }
37 |
38 | public static ByteBuffer getOutputBuffer(MediaCodec codec, int index){
39 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
40 | return codec.getOutputBuffer(index);
41 | }else{
42 | return codec.getOutputBuffers()[index];
43 | }
44 | }
45 |
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/media/MediaConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.media;
15 |
16 | /**
17 | * MediaConfig 音视频编码信息设置
18 | *
19 | * @author wuwang
20 | * @version v1.0 2017:10:26 18:28
21 | */
22 | public class MediaConfig {
23 |
24 | public Video mVideo=new Video();
25 | public Audio mAudio=new Audio();
26 |
27 | public class Video{
28 | public String mime="video/avc";
29 | public int width=368;
30 | public int height=640;
31 | public int frameRate=24;
32 | public int iframe=1;
33 | public int bitrate=1177600;
34 | public int colorFormat;
35 | }
36 |
37 | public class Audio{
38 | public String mime="audio/mp4a-latm";
39 | public int sampleRate=48000;
40 | public int channelCount=2;
41 | public int bitrate=128000;
42 | public int profile;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/media/RenderBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.media;
15 |
16 | import com.wuwang.aavt.egl.EglHelper;
17 |
18 | /**
19 | * RenderBean
20 | *
21 | * @author wuwang
22 | * @version v1.0 2017:10:27 15:02
23 | */
24 | public class RenderBean {
25 |
26 | public EglHelper egl;
27 | public int sourceWidth;
28 | public int sourceHeight;
29 | public int textureId;
30 | public boolean endFlag;
31 |
32 | public long timeStamp;
33 | public long textureTime;
34 |
35 | public long threadId;
36 |
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/media/SurfaceShower.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.media;
15 |
16 | import android.opengl.EGLSurface;
17 | import android.opengl.GLES20;
18 |
19 | import com.wuwang.aavt.core.IObserver;
20 | import com.wuwang.aavt.gl.BaseFilter;
21 | import com.wuwang.aavt.gl.LazyFilter;
22 | import com.wuwang.aavt.utils.MatrixUtils;
23 |
24 | /**
25 | * SurfaceShower 用于将RenderBean展示到指定的Surface上
26 | *
27 | * @author wuwang
28 | * @version v1.0 2017:10:27 08:53
29 | */
30 | public class SurfaceShower implements IObserver {
31 |
32 | private EGLSurface mShowSurface;
33 | private boolean isShow=false;
34 | private BaseFilter mFilter;
35 | private Object mSurface;
36 | private int mWidth;
37 | private int mHeight;
38 | private int mMatrixType= MatrixUtils.TYPE_CENTERCROP;
39 | private OnDrawEndListener mListener;
40 | private RenderBean mBean;
41 |
42 | public void setOutputSize(int width,int height){
43 | this.mWidth=width;
44 | this.mHeight=height;
45 | }
46 |
47 | private void clearSurface() {
48 | if(mShowSurface!=null){
49 | mBean.egl.destroySurface(mShowSurface);
50 | mShowSurface = null;
51 | }
52 | }
53 |
54 | /**
55 | * 设置输出的Surface
56 | * @param surface {@link android.view.Surface}、{@link android.graphics.SurfaceTexture}或{@link android.view.TextureView}
57 | */
58 | public void setSurface(Object surface){
59 | this.mSurface=surface;
60 | clearSurface();
61 | }
62 |
63 | /**
64 | * 设置矩阵变换类型
65 | * @param type 变换类型,{@link MatrixUtils#TYPE_FITXY},{@link MatrixUtils#TYPE_FITSTART},{@link MatrixUtils#TYPE_CENTERCROP},{@link MatrixUtils#TYPE_CENTERINSIDE}或{@link MatrixUtils#TYPE_FITEND}
66 | */
67 | public void setMatrixType(int type){
68 | this.mMatrixType=type;
69 | }
70 |
71 | public void open(){
72 | isShow=true;
73 | }
74 |
75 | public void close(){
76 | isShow=false;
77 | }
78 |
79 | @Override
80 | public void onCall(RenderBean rb) {
81 | if(rb.endFlag){
82 | clearSurface();
83 | }else if(isShow&&mSurface!=null){
84 | if(mShowSurface==null){
85 | mBean = rb;
86 | mShowSurface=rb.egl.createWindowSurface(mSurface);
87 | mFilter=new LazyFilter();
88 | mFilter.create();
89 | mFilter.sizeChanged(rb.sourceWidth, rb.sourceHeight);
90 | MatrixUtils.getMatrix(mFilter.getVertexMatrix(),mMatrixType,rb.sourceWidth,rb.sourceHeight,
91 | mWidth,mHeight);
92 | MatrixUtils.flip(mFilter.getVertexMatrix(),false,true);
93 | }
94 | rb.egl.makeCurrent(mShowSurface);
95 | GLES20.glViewport(0,0,mWidth,mHeight);
96 | mFilter.draw(rb.textureId);
97 | if(mListener!=null){
98 | mListener.onDrawEnd(mShowSurface,rb);
99 | }
100 | rb.egl.swapBuffers(mShowSurface);
101 | }
102 | }
103 |
104 | /**
105 | * 设置单帧渲染完成监听器
106 | * @param listener 监听器
107 | */
108 | public void setOnDrawEndListener(OnDrawEndListener listener){
109 | this.mListener=listener;
110 | }
111 |
112 | public interface OnDrawEndListener{
113 | /**
114 | * 渲染完成通知
115 | * @param surface 渲染的目标EGLSurface
116 | * @param bean 渲染用的资源
117 | */
118 | void onDrawEnd(EGLSurface surface,RenderBean bean);
119 | }
120 |
121 | }
122 |
123 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/media/WrapRenderer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.media;
15 |
16 | import com.wuwang.aavt.core.Renderer;
17 | import com.wuwang.aavt.gl.OesFilter;
18 | import com.wuwang.aavt.utils.MatrixUtils;
19 |
20 |
21 | /**
22 | * WrapRenderer 用于包装其他Filter渲染OES纹理
23 | *
24 | * @author wuwang
25 | * @version v1.0 2017:10:27 08:53
26 | */
27 | public class WrapRenderer implements Renderer {
28 |
29 | private Renderer mRenderer;
30 | private OesFilter mFilter;
31 |
32 | public static final int TYPE_MOVE=0;
33 | public static final int TYPE_CAMERA=1;
34 |
35 | public WrapRenderer(Renderer renderer){
36 | this.mRenderer=renderer;
37 | mFilter=new OesFilter();
38 | setFlag(TYPE_MOVE);
39 | }
40 |
41 | public void setFlag(int flag){
42 | if(flag==TYPE_MOVE){
43 | mFilter.setVertexCo(new float[]{
44 | -1.0f,1.0f,
45 | -1.0f,-1.0f,
46 | 1.0f,1.0f,
47 | 1.0f,-1.0f,
48 | });
49 | }else if(flag==TYPE_CAMERA){
50 | mFilter.setVertexCo(new float[]{
51 | -1.0f, -1.0f,
52 | 1.0f, -1.0f,
53 | -1.0f, 1.0f,
54 | 1.0f, 1.0f,
55 | });
56 | }
57 | }
58 |
59 | public float[] getTextureMatrix(){
60 | return mFilter.getTextureMatrix();
61 | }
62 |
63 | @Override
64 | public void create() {
65 | mFilter.create();
66 | if(mRenderer!=null){
67 | mRenderer.create();
68 | }
69 | }
70 |
71 | @Override
72 | public void sizeChanged(int width, int height) {
73 | mFilter.sizeChanged(width, height);
74 | if(mRenderer!=null){
75 | mRenderer.sizeChanged(width, height);
76 | }
77 | }
78 |
79 | @Override
80 | public void draw(int texture) {
81 | if(mRenderer!=null){
82 | mRenderer.draw(mFilter.drawToTexture(texture));
83 | }else{
84 | mFilter.draw(texture);
85 | }
86 | }
87 |
88 | @Override
89 | public void destroy() {
90 | if(mRenderer!=null){
91 | mRenderer.destroy();
92 | }
93 | mFilter.destroy();
94 | }
95 | }
96 |
97 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/media/audio/FileAudioProvider.java:
--------------------------------------------------------------------------------
1 | package com.wuwang.aavt.media.audio;
2 |
3 | import android.annotation.TargetApi;
4 | import android.media.MediaCodec;
5 | import android.media.MediaExtractor;
6 | import android.media.MediaFormat;
7 | import android.os.Build;
8 | import android.support.annotation.NonNull;
9 | import android.support.annotation.RequiresApi;
10 |
11 | import com.wuwang.aavt.media.CodecUtil;
12 |
13 | import java.io.IOException;
14 | import java.nio.ByteBuffer;
15 |
16 | /**
17 | * @author wuwang
18 | * @version 1.00 , 2019/03/13
19 | */
20 |
21 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
22 | public class FileAudioProvider extends MediaCodec.Callback implements ISoundProvider {
23 |
24 | private MediaExtractor extractor;
25 | private MediaCodec codec;
26 | private int audioTrack = -1;
27 | private MediaFormat format;
28 | private final long TIME_US = 1000;
29 |
30 | private FileAudioProvider(){}
31 |
32 | @Override
33 | public void onInputBufferAvailable(@NonNull MediaCodec codec, int index) {
34 | ByteBuffer buffer = CodecUtil.getInputBuffer(codec,index);
35 | buffer.clear();
36 | int size = extractor.readSampleData(buffer,0);
37 | codec.queueInputBuffer(index,0,size ,extractor.getSampleTime(),extractor.getSampleFlags());
38 | }
39 |
40 | @Override
41 | public void onOutputBufferAvailable(@NonNull MediaCodec codec, int index, @NonNull MediaCodec.BufferInfo info) {
42 | ByteBuffer buffer = CodecUtil.getOutputBuffer(codec,index);
43 | codec.releaseOutputBuffer(index,false);
44 | }
45 |
46 | @Override
47 | public void onError(@NonNull MediaCodec codec, @NonNull MediaCodec.CodecException e) {
48 |
49 | }
50 |
51 | @Override
52 | public void onOutputFormatChanged(@NonNull MediaCodec codec, @NonNull MediaFormat format) {
53 |
54 | }
55 |
56 | private boolean setPath(String path){
57 | try {
58 | extractor = new MediaExtractor();
59 | extractor.setDataSource(path);
60 | int count = extractor.getTrackCount();
61 | if(count <= 0){
62 | return false;
63 | }
64 | for (int i=0;i=0){
96 | ByteBuffer buffer = CodecUtil.getInputBuffer(codec,inputId);
97 | buffer.clear();
98 |
99 | }
100 | }
101 |
102 | @Override
103 | public void close() {
104 | codec.stop();
105 | codec.release();
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/media/audio/ISoundProvider.java:
--------------------------------------------------------------------------------
1 | package com.wuwang.aavt.media.audio;
2 |
3 | import com.wuwang.aavt.media.av.ICloseable;
4 |
5 | /**
6 | * @author wuwang
7 | * @version 1.00 , 2019/03/13
8 | */
9 | public interface ISoundProvider extends ICloseable {
10 |
11 | void open();
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/media/audio/MicAudioProvider.java:
--------------------------------------------------------------------------------
1 | package com.wuwang.aavt.media.audio;
2 |
3 | import android.media.AudioFormat;
4 | import android.media.AudioRecord;
5 | import android.media.MediaRecorder;
6 |
7 | import com.wuwang.aavt.media.audio.ISoundProvider;
8 | import com.wuwang.aavt.media.av.AvException;
9 |
10 | /**
11 | * @author wuwang
12 | * @version 1.00 , 2019/03/13
13 | */
14 | public class MicAudioProvider implements ISoundProvider {
15 |
16 | private AudioRecord record;
17 | private int recordBufferSize=0;
18 | private int sampleRateInHz=48000; //音频采样率
19 | private int channelConfig= AudioFormat.CHANNEL_IN_STEREO; //音频录制通道,默认为立体声
20 | private int audioFormat=AudioFormat.ENCODING_PCM_16BIT; //音频录制格式,默认为PCM16Bit
21 |
22 | public MicAudioProvider(){
23 | setProperty(sampleRateInHz,channelConfig,audioFormat);
24 | }
25 |
26 | public MicAudioProvider(int sampleRateInHz, int channelConfig, int audioFormat){
27 | setProperty(sampleRateInHz, channelConfig, audioFormat);
28 | }
29 |
30 | public void setProperty(int sampleRateInHz, int channelConfig, int audioFormat){
31 | this.sampleRateInHz = sampleRateInHz;
32 | this.channelConfig = channelConfig;
33 | this.audioFormat = audioFormat;
34 | this.recordBufferSize = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat) * 2;
35 | }
36 |
37 | @Override
38 | public void open() {
39 | close();
40 | record = new AudioRecord(MediaRecorder.AudioSource.MIC,sampleRateInHz,channelConfig,audioFormat,recordBufferSize);
41 | record.startRecording();
42 | }
43 |
44 | @Override
45 | public void close() {
46 | if(record != null){
47 | record.stop();
48 | record.release();
49 | record = null;
50 | }
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/media/av/AvException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.media.av;
15 |
16 | /**
17 | * AVException
18 | *
19 | * @author wuwang
20 | * @version v1.0 2017:10:28 17:27
21 | */
22 | public class AvException extends Exception {
23 |
24 | public AvException(){
25 | super();
26 | }
27 |
28 | public AvException(String msg){
29 | super("AVException:"+msg);
30 | }
31 |
32 | public AvException(String message, Throwable cause) {
33 | super("AVException:"+message, cause);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/media/av/ICloseable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.media.av;
15 |
16 | /**
17 | * ICloseable
18 | *
19 | * @author wuwang
20 | * @version v1.0 2017:10:28 17:25
21 | */
22 | public interface ICloseable {
23 |
24 | void close();
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/aavt/src/main/java/com/wuwang/aavt/media/av/IStore.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package com.wuwang.aavt.media.av;
15 |
16 | /**
17 | * IStore 文件存储接口
18 | *
19 | * @author wuwang
20 | * @version v1.0 2017:10:28 16:39
21 | */
22 | public interface IStore