Universal UVCCamera library,supporting recording, pushing, etc
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
蒋东国 31a95a8627
Update README.md
7 years ago
.gradle Initial commit 7 years ago
.idea tijiao 7 years ago
app 重构拍摄图片模块,解决分辨率不匹配问题 7 years ago
build/generated tijiao 7 years ago
gradle/wrapper Initial commit 7 years ago
libusbcamera 重构拍摄图片模块,解决分辨率不匹配问题 7 years ago
AndroidUSBCamera.iml Initial commit 7 years ago
LICENSE Create LICENSE 7 years ago
README.md Update README.md 7 years ago
build.gradle 重构项目,包括内存泄漏优化,分辨率切换,画面尺寸等 7 years ago
gradle.properties Initial commit 7 years ago
gradlew Initial commit 7 years ago
gradlew.bat Initial commit 7 years ago
local.properties xuigai 7 years ago
settings.gradle Initial commit 7 years ago

README.md

OkCamera

AndroidUSBCamera is developed based on the saki4510t/UVCCamera, the project of USB Camera (UVC equipment) and the use of video data acquisition are highly packaged, and it can help developers using USB Camera devices easily by a few simple APIs. By using AndroidUSBCamera,you can detect and connect to a USB Camera simply.And you also can use it to realize taking picture,recording mp4,switching resolutions and setting  camera's contrast or brightness,etc.

中文文档: AndroidUSBCamera,UVCCamera开发通用库

Usage

1.Add to your Android Studio project

Step 1. Add the JitPack repository to your build file.Add it in your root build.gradle at the end of repositories:

allprojects {
		repositories {
			...
			maven { url 'http://raw.github.com/saki4510t/libcommon/master/repository/' }
			maven { url 'https://jitpack.io' }
		}
	}

Step 2. Add the dependency

dependencies { 
	    compile 'com.github.jiangdongguo:AndroidUSBCamera:2.0'
}  

2. APIs Introduction

(1) In order to using it correctly,the following four steps must be achieved:

mUVCCameraView = (CameraViewInterface) mTextureView;
mUVCCameraView.setCallback(mCallback);
mCameraHelper = UVCCameraHelper.getInstance();
mCameraHelper.initUSBMonitor(this, mUVCCameraView, mDevConnectListener); 

To be attention,mCallback is a object of interface CameraViewInterface.Callback,and it's used to be listenering surfaceView created or detoryed.mDevConnectListener is a object of interface UVCCameraHelper.OnMyDevConnectListener,and it's used to be listenering to detect and conntect USB device.Here is the coding order:

private CameraViewInterface.Callback mCallback = new CameraViewInterface.Callback mCallback(){
    @Override
    public void onSurfaceCreated(CameraViewInterface view, Surface surface) {
        // must have
        if (!isPreview && mCameraHelper.isCameraOpened()) {
            mCameraHelper.startPreview(mUVCCameraView);
            isPreview = true;
        }
    }

    @Override
    public void onSurfaceChanged(CameraViewInterface view, Surface surface, int width, int height) {

    }

    @Override
    public void onSurfaceDestroy(CameraViewInterface view, Surface surface) {
        // must have
        if (isPreview && mCameraHelper.isCameraOpened()) {
            mCameraHelper.stopPreview();
            isPreview = false;
        }
    }
}
private UVCCameraHelper.OnMyDevConnectListener listener = new UVCCameraHelper.OnMyDevConnectListener() {

        @Override
        public void onAttachDev(UsbDevice device) {
            // request open permission(must have)
            if (!isRequest) {
                isRequest = true;
                if (mCameraHelper != null) {
                    mCameraHelper.requestPermission(0);
                }
            }
        }

        @Override
        public void onDettachDev(UsbDevice device) {
            // close camera(must have)
            if (isRequest) {
                isRequest = false;
                mCameraHelper.closeCamera();
            }
        }

        @Override
        public void onConnectDev(UsbDevice device, boolean isConnected) {
       	
        }

        @Override
        public void onDisConnectDev(UsbDevice device) {
          
        }
    };

(2) Capturing JPG Images

 mCameraHelper.capturePicture(picPath, new AbstractUVCCameraHandler.OnCaptureListener() {
                    @Override
                    public void onCaptureResult(String path) {
                        Log.i(TAG,"save path:" + path);
                    }
                }); 

(3) Recording Mp4,supporting close voice and save file automatic.

RecordParams params = new RecordParams();
                    params.setRecordPath(videoPath);
                    params.setRecordDuration(0);                        // 0,do not cut save
                    params.setVoiceClose(mSwitchVoice.isChecked());    // is close voice
                    mCameraHelper.startRecording(params, new AbstractUVCCameraHandler.OnEncodeResultListener() {
                        @Override
                        public void onEncodeResult(byte[] data, int offset, int length, long timestamp, int type) {
                            // type = 1,h264 video stream
                            if (type == 1) {
//                                FileUtils.putFileStream(data, offset, length);
                            }
                            // type = 0,aac audio stream
                            if(type == 0) {

                            }
                        }

                        @Override
                        public void onRecordResult(String videoPath) {
                            Log.i(TAG,"videoPath = "+videoPath);
                        }
                    });  

(4) setting camera's brightness and contrast.

mCameraHelper.setModelValue(UVCCameraHelper.MODE_BRIGHTNESS,progress);
mCameraHelper.setModelValue(UVCCameraHelper.MODE_CONTRAST,progress);
mCameraHelper.getModelValue(UVCCameraHelper.MODE_BRIGHTNESS);
mCameraHelper.getModelValue(UVCCameraHelper.MODE_CONTRAST);
...

(5) switch resolutions and camera.

mCameraHelper.updateResolution(widht, height);

At last,remember adding permissions:  

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

License

Copyright 2018 Jiangdongguo

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.