├── lib-camera ├── .gitignore ├── consumer-rules.pro ├── libs │ ├── arm64-v8a │ │ └── libyuv.so │ └── armeabi-v7a │ │ └── libyuv.so ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── android │ │ │ └── xz │ │ │ ├── camera │ │ │ ├── YUVFormat.java │ │ │ ├── callback │ │ │ │ ├── PictureBufferCallback.java │ │ │ │ ├── PreviewBufferCallback.java │ │ │ │ └── CameraCallback.java │ │ │ ├── view │ │ │ │ ├── base │ │ │ │ │ ├── BaseCameraView.java │ │ │ │ │ ├── BaseSurfaceView.java │ │ │ │ │ ├── RenderHandler.java │ │ │ │ │ └── BaseTextureView.java │ │ │ │ ├── CameraGLSurfaceView.java │ │ │ │ ├── Camera2GLSurfaceView.java │ │ │ │ ├── CameraGLESSurfaceView.java │ │ │ │ ├── Camera2GLESSurfaceView.java │ │ │ │ ├── CameraTextureView.java │ │ │ │ ├── Camera2TextureView.java │ │ │ │ ├── CameraGLTextureView.java │ │ │ │ ├── Camera2GLTextureView.java │ │ │ │ ├── CameraSurfaceView.java │ │ │ │ └── Camera2SurfaceView.java │ │ │ └── ICameraManager.java │ │ │ ├── encoder │ │ │ ├── MediaRecordListener.java │ │ │ ├── IAudioEncoder.java │ │ │ ├── IVideoEncoder.java │ │ │ ├── TextureEncoder.java │ │ │ ├── BufferMovieEncoder.java │ │ │ ├── MediaMuxerWrapper.java │ │ │ └── MediaSurfaceEncoder.java │ │ │ ├── gles │ │ │ ├── filiter │ │ │ │ ├── AFilter.java │ │ │ │ └── Texture2DFilter.java │ │ │ ├── WindowSurface.java │ │ │ ├── MatrixUtils.java │ │ │ └── EglSurfaceBase.java │ │ │ ├── permission │ │ │ └── IPermissionsResult.java │ │ │ └── util │ │ │ └── YUVUtils.java │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── app ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── colors.xml │ │ │ └── themes.xml │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.webp │ │ │ └── ic_launcher_round.webp │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.webp │ │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.webp │ │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.webp │ │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.webp │ │ │ └── ic_launcher_round.webp │ │ ├── drawable-xhdpi │ │ │ └── ic_switch_camera.png │ │ ├── drawable-xxhdpi │ │ │ └── ic_switch_camera.png │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── layout │ │ │ ├── activity_camera.xml │ │ │ ├── activity_display_media.xml │ │ │ ├── activity_texture_camera.xml │ │ │ ├── activity_glsurface_camera.xml │ │ │ ├── activity_glsurface_camera2.xml │ │ │ ├── activity_gltexture_camera.xml │ │ │ ├── activity_gltexture_camera2.xml │ │ │ ├── activity_surface_camera2.xml │ │ │ ├── activity_texture_camera2.xml │ │ │ ├── activity_glessurface_camera.xml │ │ │ ├── activity_glessurface_camera2.xml │ │ │ ├── activity_surface_camera.xml │ │ │ ├── activity_media_codec_surface.xml │ │ │ ├── activity_media_codec_buffer.xml │ │ │ └── activity_main.xml │ │ ├── drawable │ │ │ ├── img_switch_normal.xml │ │ │ ├── tv_timer_bg.xml │ │ │ ├── img_switch_pressed.xml │ │ │ ├── btn_capture_normal.xml │ │ │ ├── btn_capture_pressed.xml │ │ │ ├── img_switch_bg.xml │ │ │ ├── btn_capture_bg.xml │ │ │ └── ic_launcher_background.xml │ │ ├── xml │ │ │ ├── backup_rules.xml │ │ │ └── data_extraction_rules.xml │ │ ├── values-night │ │ │ └── themes.xml │ │ └── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ └── com │ │ │ └── android │ │ │ └── xz │ │ │ └── camerademo │ │ │ ├── CameraActivity.java │ │ │ ├── MediaDisplayActivity.java │ │ │ ├── base │ │ │ └── BaseCameraActivity.java │ │ │ ├── util │ │ │ └── ScreenTools.java │ │ │ ├── MainActivity.java │ │ │ ├── mediacodec_activity │ │ │ ├── MediaCodecBufferActivity.java │ │ │ └── MediaCodecSurfaceActivity.java │ │ │ └── view │ │ │ └── CaptureButton.java │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── img ├── camera.jpg └── index.jpg ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── settings.gradle ├── gradle.properties ├── gradlew.bat ├── README.md └── gradlew /lib-camera/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /lib-camera/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /release 3 | -------------------------------------------------------------------------------- /img/camera.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/img/camera.jpg -------------------------------------------------------------------------------- /img/index.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/img/index.jpg -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AndroidCamera 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /lib-camera/libs/arm64-v8a/libyuv.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/lib-camera/libs/arm64-v8a/libyuv.so -------------------------------------------------------------------------------- /lib-camera/libs/armeabi-v7a/libyuv.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/lib-camera/libs/armeabi-v7a/libyuv.so -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/camera/YUVFormat.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.camera; 2 | 3 | public enum YUVFormat { 4 | I420, NV21 5 | } 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_switch_camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/app/src/main/res/drawable-xhdpi/ic_switch_camera.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_switch_camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/app/src/main/res/drawable-xxhdpi/ic_switch_camera.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaozhi003/AndroidCamera/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FF000000 4 | #FFFFFFFF 5 | -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/encoder/MediaRecordListener.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.encoder; 2 | 3 | public interface MediaRecordListener { 4 | void onStart(); 5 | 6 | void onStopped(String videoPath); 7 | } 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Aug 15 17:02:37 CST 2024 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/camera/callback/PictureBufferCallback.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.camera.callback; 2 | 3 | /** 4 | * 摄像头拍照回调 5 | * 6 | * @author xiaozhi 7 | * @since 2024/8/30 8 | */ 9 | public interface PictureBufferCallback { 10 | 11 | void onPictureToken(byte[] data); 12 | } 13 | -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/gles/filiter/AFilter.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.gles.filiter; 2 | 3 | public interface AFilter { 4 | 5 | void surfaceCreated(); 6 | 7 | void surfaceChanged(int width, int height); 8 | 9 | int draw(int textureId, float[] matrix); 10 | 11 | void release(); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/camera/callback/PreviewBufferCallback.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.camera.callback; 2 | 3 | import com.android.xz.camera.YUVFormat; 4 | 5 | /** 6 | * 摄像头预览数据回调 7 | * 8 | * @author xiaozhi 9 | * @since 2024/8/15 10 | */ 11 | public interface PreviewBufferCallback { 12 | 13 | void onPreviewBufferFrame(byte[] data, int width, int height, YUVFormat format); 14 | } 15 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | gradlePluginPortal() 6 | } 7 | } 8 | dependencyResolutionManagement { 9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 10 | repositories { 11 | google() 12 | mavenCentral() 13 | } 14 | } 15 | rootProject.name = "AndroidCamera" 16 | include ':app' 17 | include ':lib-camera' 18 | -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/permission/IPermissionsResult.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.permission; 2 | 3 | /** 4 | * 权限申请的结果回调 5 | * 6 | * @author xiaozhi 7 | * @since 2023/5/16 8 | */ 9 | public interface IPermissionsResult { 10 | 11 | /** 12 | * 权限申请成功 13 | */ 14 | void passPermissions(); 15 | 16 | /** 17 | * 权限申请失败 18 | */ 19 | void forbidPermissions(); 20 | } 21 | -------------------------------------------------------------------------------- /lib-camera/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/camera/view/base/BaseCameraView.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.camera.view.base; 2 | 3 | import com.android.xz.camera.ICameraManager; 4 | 5 | /** 6 | * Camera预览View通用接口 7 | * 8 | * @author xiaozhi 9 | * @since 2024/8/30 10 | */ 11 | public interface BaseCameraView { 12 | 13 | ICameraManager getCameraManager(); 14 | 15 | void onResume(); 16 | 17 | void onPause(); 18 | 19 | void onDestroy(); 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_camera.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/img_switch_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/tv_timer_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/img_switch_pressed.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_capture_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_capture_pressed.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 18 | 19 | -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/camera/callback/CameraCallback.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.camera.callback; 2 | 3 | import android.hardware.Camera; 4 | 5 | /** 6 | * 摄像头打开预览等回调 7 | * 8 | * @author xiaozhi 9 | * @since 2024/8/15 10 | */ 11 | public interface CameraCallback { 12 | 13 | void onOpen(); 14 | 15 | void onOpenError(int error, String msg); 16 | 17 | void onPreview(int previewWidth, int previewHeight); 18 | 19 | void onPreviewError(int error, String msg); 20 | 21 | void onClose(); 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/res/xml/backup_rules.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/img_switch_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_capture_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/xml/data_extraction_rules.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 12 | 13 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/xz/camerademo/CameraActivity.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.camerademo; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | 8 | import com.android.xz.camerademo.base.BaseCameraActivity; 9 | 10 | public class CameraActivity extends BaseCameraActivity { 11 | 12 | public static final String EXTRA_LAYOUT_ID = "com.android.xz.camera.EXTRA_LAYOUT_ID"; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | } 18 | 19 | @Override 20 | public int getLayoutId() { 21 | Intent intent = getIntent(); 22 | return intent.getIntExtra(EXTRA_LAYOUT_ID, R.layout.activity_surface_camera); 23 | } 24 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /lib-camera/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_display_media.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 20 | 21 | -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/camera/view/CameraGLSurfaceView.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.camera.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import com.android.xz.camera.CameraManager; 7 | import com.android.xz.camera.ICameraManager; 8 | import com.android.xz.camera.view.base.BaseGLSurfaceView; 9 | 10 | /** 11 | * 适用Camera的GLSurfaceView预览 12 | * 13 | * @author xiaozhi 14 | * @since 2024/8/22 15 | */ 16 | public class CameraGLSurfaceView extends BaseGLSurfaceView { 17 | 18 | public CameraGLSurfaceView(Context context) { 19 | super(context); 20 | } 21 | 22 | public CameraGLSurfaceView(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | } 25 | 26 | @Override 27 | public ICameraManager createCameraManager(Context context) { 28 | // 创建CameraManager 29 | return new CameraManager(context); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/camera/view/Camera2GLSurfaceView.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.camera.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import com.android.xz.camera.Camera2Manager; 7 | import com.android.xz.camera.ICameraManager; 8 | import com.android.xz.camera.view.base.BaseGLSurfaceView; 9 | 10 | /** 11 | * 适用Camera2的GLSurfaceView 12 | * 13 | * @author xiaozhi 14 | * @since 2024/8/22 15 | */ 16 | public class Camera2GLSurfaceView extends BaseGLSurfaceView { 17 | 18 | public Camera2GLSurfaceView(Context context) { 19 | super(context); 20 | } 21 | 22 | public Camera2GLSurfaceView(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | } 25 | 26 | @Override 27 | public ICameraManager createCameraManager(Context context) { 28 | // 创建Camera2Manager 29 | return new Camera2Manager(context); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/camera/view/CameraGLESSurfaceView.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.camera.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import com.android.xz.camera.CameraManager; 7 | import com.android.xz.camera.ICameraManager; 8 | import com.android.xz.camera.view.base.BaseGLESSurfaceView; 9 | 10 | /** 11 | * 适用Camera的SurfaceView,自定义opengl 12 | * 13 | * @author xiaozhi 14 | * @since 2024/8/22 15 | */ 16 | public class CameraGLESSurfaceView extends BaseGLESSurfaceView { 17 | 18 | public CameraGLESSurfaceView(Context context) { 19 | super(context); 20 | } 21 | 22 | public CameraGLESSurfaceView(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | } 25 | 26 | public CameraGLESSurfaceView(Context context, AttributeSet attrs, int defStyleAttr) { 27 | super(context, attrs, defStyleAttr); 28 | } 29 | 30 | @Override 31 | public ICameraManager createCameraManager(Context context) { 32 | return new CameraManager(context); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | } 4 | 5 | android { 6 | namespace 'com.android.xz.camerademo' 7 | compileSdk 34 8 | 9 | defaultConfig { 10 | applicationId "com.android.xz.camerademo" 11 | minSdk 21 12 | targetSdk 33 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_1_8 27 | targetCompatibility JavaVersion.VERSION_1_8 28 | } 29 | } 30 | 31 | dependencies { 32 | implementation 'androidx.appcompat:appcompat:1.6.1' 33 | implementation 'com.google.android.material:material:1.5.0' 34 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 35 | implementation project(':lib-camera') 36 | } -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/camera/view/Camera2GLESSurfaceView.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.camera.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import com.android.xz.camera.Camera2Manager; 7 | import com.android.xz.camera.ICameraManager; 8 | import com.android.xz.camera.view.base.BaseGLESSurfaceView; 9 | 10 | /** 11 | * 适用Camera2的SurfaceView,自定义opengl 12 | * 13 | * @author xiaozhi 14 | * @since 2024/8/22 15 | */ 16 | public class Camera2GLESSurfaceView extends BaseGLESSurfaceView { 17 | 18 | public Camera2GLESSurfaceView(Context context) { 19 | super(context); 20 | } 21 | 22 | public Camera2GLESSurfaceView(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | } 25 | 26 | public Camera2GLESSurfaceView(Context context, AttributeSet attrs, int defStyleAttr) { 27 | super(context, attrs, defStyleAttr); 28 | } 29 | 30 | @Override 31 | public ICameraManager createCameraManager(Context context) { 32 | return new Camera2Manager(context); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/camera/view/CameraTextureView.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.camera.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import com.android.xz.camera.CameraManager; 7 | import com.android.xz.camera.ICameraManager; 8 | import com.android.xz.camera.view.base.BaseTextureView; 9 | 10 | /** 11 | * 适用Camera的TextureView 12 | * 13 | * @author xiaozhi 14 | * @since 2024/8/22 15 | */ 16 | public class CameraTextureView extends BaseTextureView { 17 | 18 | public CameraTextureView(Context context) { 19 | super(context); 20 | } 21 | 22 | public CameraTextureView(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | } 25 | 26 | public CameraTextureView(Context context, AttributeSet attrs, int defStyleAttr) { 27 | super(context, attrs, defStyleAttr); 28 | } 29 | 30 | @Override 31 | public ICameraManager createCameraManager(Context context) { 32 | // 创建CameraManager 33 | return new CameraManager(context); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/camera/view/Camera2TextureView.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.camera.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import com.android.xz.camera.Camera2Manager; 7 | import com.android.xz.camera.ICameraManager; 8 | import com.android.xz.camera.view.base.BaseTextureView; 9 | 10 | /** 11 | * 适用Camera2的TextureView 12 | * 13 | * @author xiaozhi 14 | * @since 2024/8/22 15 | */ 16 | public class Camera2TextureView extends BaseTextureView { 17 | 18 | public Camera2TextureView(Context context) { 19 | super(context); 20 | } 21 | 22 | public Camera2TextureView(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | } 25 | 26 | public Camera2TextureView(Context context, AttributeSet attrs, int defStyleAttr) { 27 | super(context, attrs, defStyleAttr); 28 | } 29 | 30 | @Override 31 | public ICameraManager createCameraManager(Context context) { 32 | // 创建Camera2Manager 33 | return new Camera2Manager(context); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib-camera/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | } 4 | 5 | android { 6 | namespace 'com.android.xz' 7 | compileSdk 34 8 | 9 | defaultConfig { 10 | minSdk 21 11 | targetSdk 34 12 | 13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 14 | consumerProguardFiles "consumer-rules.pro" 15 | 16 | ndk { 17 | abiFilters "armeabi-v7a", "arm64-v8a" 18 | } 19 | } 20 | 21 | buildTypes { 22 | release { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | compileOptions { 28 | sourceCompatibility JavaVersion.VERSION_1_8 29 | targetCompatibility JavaVersion.VERSION_1_8 30 | } 31 | 32 | sourceSets { 33 | main { 34 | jniLibs.srcDirs = ['libs'] 35 | } 36 | } 37 | } 38 | 39 | dependencies { 40 | 41 | implementation 'androidx.appcompat:appcompat:1.6.1' 42 | implementation 'com.google.android.material:material:1.12.0' 43 | implementation "androidx.exifinterface:exifinterface:1.3.7" 44 | } -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/encoder/IAudioEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * UVCCamera 3 | * library and sample to access to UVC web camera on non-rooted Android device 4 | * 5 | * Copyright (c) 2014-2017 saki t_saki@serenegiant.com 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * All files in the folder are under this Apache License, Version 2.0. 20 | * Files in the libjpeg-turbo, libusb, libuvc, rapidjson folder 21 | * may have a different license, see the respective files. 22 | */ 23 | 24 | package com.android.xz.encoder; 25 | 26 | public interface IAudioEncoder { 27 | } 28 | -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/camera/view/CameraGLTextureView.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.camera.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import androidx.annotation.NonNull; 7 | import androidx.annotation.Nullable; 8 | 9 | import com.android.xz.camera.CameraManager; 10 | import com.android.xz.camera.ICameraManager; 11 | import com.android.xz.camera.view.base.BaseGLTextureView; 12 | 13 | /** 14 | * 适用Camera的TextureView,自定义opengl 15 | * 16 | * @author xiaozhi 17 | * @since 2024/8/22 18 | */ 19 | public class CameraGLTextureView extends BaseGLTextureView { 20 | 21 | public CameraGLTextureView(@NonNull Context context) { 22 | super(context); 23 | } 24 | 25 | public CameraGLTextureView(@NonNull Context context, @Nullable AttributeSet attrs) { 26 | super(context, attrs); 27 | } 28 | 29 | public CameraGLTextureView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 30 | super(context, attrs, defStyleAttr); 31 | } 32 | 33 | @Override 34 | public ICameraManager createCameraManager(Context context) { 35 | return new CameraManager(context); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/camera/view/Camera2GLTextureView.java: -------------------------------------------------------------------------------- 1 | package com.android.xz.camera.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import androidx.annotation.NonNull; 7 | import androidx.annotation.Nullable; 8 | 9 | import com.android.xz.camera.Camera2Manager; 10 | import com.android.xz.camera.ICameraManager; 11 | import com.android.xz.camera.view.base.BaseGLTextureView; 12 | 13 | /** 14 | * 适用Camera2的TextureView,自定义opengl 15 | * 16 | * @author xiaozhi 17 | * @since 2024/8/22 18 | */ 19 | public class Camera2GLTextureView extends BaseGLTextureView { 20 | 21 | public Camera2GLTextureView(@NonNull Context context) { 22 | super(context); 23 | } 24 | 25 | public Camera2GLTextureView(@NonNull Context context, @Nullable AttributeSet attrs) { 26 | super(context, attrs); 27 | } 28 | 29 | public Camera2GLTextureView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 30 | super(context, attrs, defStyleAttr); 31 | } 32 | 33 | @Override 34 | public ICameraManager createCameraManager(Context context) { 35 | return new Camera2Manager(context); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib-camera/src/main/java/com/android/xz/encoder/IVideoEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * UVCCamera 3 | * library and sample to access to UVC web camera on non-rooted Android device 4 | * 5 | * Copyright (c) 2014-2017 saki t_saki@serenegiant.com 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * All files in the folder are under this Apache License, Version 2.0. 20 | * Files in the libjpeg-turbo, libusb, libuvc, rapidjson folder 21 | * may have a different license, see the respective files. 22 | */ 23 | 24 | package com.android.xz.encoder; 25 | 26 | public interface IVideoEncoder { 27 | public boolean frameAvailableSoon(); 28 | } 29 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Enables namespacing of each library's R class so that its R class includes only the 19 | # resources declared in the library itself and none from the library's dependencies, 20 | # thereby reducing the size of the R class for that library 21 | android.nonTransitiveRClass=true 22 | android.nonFinalResIds=false -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 32 | 35 | 38 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_texture_camera.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 17 | 18 |