Skip to content

Commit

Permalink
[dev] support camera configures, like zoom/sharpness etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangdg committed Aug 4, 2022
1 parent 20026d2 commit 31412b4
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ dependencies {
implementation "com.tencent.bugly:nativecrashreport:$bugly_native_version"

// For debug online
// implementation project(':libausbc')
implementation project(':libausbc')

// demo
implementation 'com.github.jiangdongguo.AndroidUSBCamera:libausbc:3.2.4'
// implementation 'com.github.jiangdongguo.AndroidUSBCamera:libausbc:3.2.4'
}
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.cacamera.autofocus"/>

<!--bugly permission need-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" />

<uses-feature android:name="android.hardware.usb.host"/>

<application
android:name="com.jiangdg.demo.DemoApplication"
android:allowBackup="true"
Expand Down
7 changes: 1 addition & 6 deletions libausbc/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jiangdg.ausbc">

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.cacamera.autofocus"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-feature android:name="android.hardware.usb.host"/>
</manifest>
137 changes: 137 additions & 0 deletions libausbc/src/main/java/com/jiangdg/ausbc/MultiCameraClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,143 @@ class MultiCameraClient(ctx: Context, callback: IDeviceConnectCallBack?) {
mMediaMuxer = null
}

/**
* Set auto focus
*
* @param enable true enable auto focus
*/
fun setAutoFocus(enable: Boolean) {
mUvcCamera?.autoFocus = enable
}

/**
* Set auto white balance
*
* @param autoWhiteBalance true enable auto white balance
*/
fun setAutoWhiteBalance(autoWhiteBalance: Boolean) {
mUvcCamera?.autoWhiteBlance = autoWhiteBalance
}

/**
* Set zoom
*
* @param zoom zoom value, 0 means reset
*/
fun setZoom(zoom: Int) {
mUvcCamera?.zoom = zoom
}

/**
* Get zoom
*/
fun getZoom() = mUvcCamera?.zoom

/**
* Set gain
*
* @param gain gain value, 0 means reset
*/
fun setGain(gain: Int) {
mUvcCamera?.gain = gain
}

/**
* Get gain
*/
fun getGain() = mUvcCamera?.gain

/**
* Set gamma
*
* @param gamma gamma value, 0 means reset
*/
fun setGamma(gamma: Int) {
mUvcCamera?.gamma = gamma
}

/**
* Get gamma
*/
fun getGamma() = mUvcCamera?.gamma

/**
* Set brightness
*
* @param brightness brightness value, 0 means reset
*/
fun setBrightness(brightness: Int) {
mUvcCamera?.brightness = brightness
}

/**
* Get brightness
*/
fun getBrightness() = mUvcCamera?.brightness

/**
* Set contrast
*
* @param contrast contrast value, 0 means reset
*/
fun setContrast(contrast: Int) {
mUvcCamera?.contrast = contrast
}

/**
* Get contrast
*/
fun getContrast() = mUvcCamera?.contrast

/**
* Set sharpness
*
* @param sharpness sharpness value, 0 means reset
*/
fun setSharpness(sharpness: Int) {
mUvcCamera?.sharpness = sharpness
}

/**
* Get sharpness
*/
fun getSharpness() = mUvcCamera?.sharpness

/**
* Set saturation
*
* @param saturation saturation value, 0 means reset
*/
fun setSaturation(saturation: Int) {
mUvcCamera?.saturation = saturation
}

/**
* Get saturation
*/
fun getSaturation() = mUvcCamera?.saturation

/**
* Set hue
*
* @param hue hue value, 0 means reset
*/
fun setHue(hue: Int) {
mUvcCamera?.hue = hue
}

/**
* Get hue
*/
fun getHue() = mUvcCamera?.hue

/**
* Get real preview size
*
* @return see [PreviewSize]
*/
fun getPreviewSize() = mPreviewSize

/**
* Set usb control block, when the uvc device was granted permission
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,9 @@ abstract class MultiCameraActivity: BaseActivity() {
* Get all usb device list
*/
protected fun getDeviceList() = mCameraClient?.getDeviceList()

/**
* Get camera client
*/
protected fun getCameraClient() = mCameraClient
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ abstract class MultiCameraFragment: BaseFragment() {
*/
protected fun getDeviceList() = mCameraClient?.getDeviceList()

/**
* Get camera client
*/
protected fun getCameraClient() = mCameraClient

/**
* Request permission
*
Expand Down
130 changes: 130 additions & 0 deletions libausbc/src/main/java/com/jiangdg/ausbc/camera/CameraUvcStrategy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,136 @@ class CameraUvcStrategy(ctx: Context) : ICameraStrategy(ctx) {
}
}

/**
* Set auto focus
*
* @param enable true enable auto focus
*/
fun setAutoFocus(enable: Boolean) {
mUVCCamera?.autoFocus = enable
}

/**
* Set auto white balance
*
* @param autoWhiteBalance true enable auto white balance
*/
fun setAutoWhiteBalance(autoWhiteBalance: Boolean) {
mUVCCamera?.autoWhiteBlance = autoWhiteBalance
}

/**
* Set zoom
*
* @param zoom zoom value, 0 means reset
*/
fun setZoom(zoom: Int) {
mUVCCamera?.zoom = zoom
}

/**
* Get zoom
*/
fun getZoom() = mUVCCamera?.zoom

/**
* Set gain
*
* @param gain gain value, 0 means reset
*/
fun setGain(gain: Int) {
mUVCCamera?.gain = gain
}

/**
* Get gain
*/
fun getGain() = mUVCCamera?.gain

/**
* Set gamma
*
* @param gamma gamma value, 0 means reset
*/
fun setGamma(gamma: Int) {
mUVCCamera?.gamma = gamma
}

/**
* Get gamma
*/
fun getGamma() = mUVCCamera?.gamma

/**
* Set brightness
*
* @param brightness brightness value, 0 means reset
*/
fun setBrightness(brightness: Int) {
mUVCCamera?.brightness = brightness
}

/**
* Get brightness
*/
fun getBrightness() = mUVCCamera?.brightness

/**
* Set contrast
*
* @param contrast contrast value, 0 means reset
*/
fun setContrast(contrast: Int) {
mUVCCamera?.contrast = contrast
}

/**
* Get contrast
*/
fun getContrast() = mUVCCamera?.contrast

/**
* Set sharpness
*
* @param sharpness sharpness value, 0 means reset
*/
fun setSharpness(sharpness: Int) {
mUVCCamera?.sharpness = sharpness
}

/**
* Get sharpness
*/
fun getSharpness() = mUVCCamera?.sharpness

/**
* Set saturation
*
* @param saturation saturation value, 0 means reset
*/
fun setSaturation(saturation: Int) {
mUVCCamera?.saturation = saturation
}

/**
* Get saturation
*/
fun getSaturation() = mUVCCamera?.saturation

/**
* Set hue
*
* @param hue hue value, 0 means reset
*/
fun setHue(hue: Int) {
mUVCCamera?.hue = hue
}

/**
* Get hue
*/
fun getHue() = mUVCCamera?.hue

private fun getUsbDeviceListInternal(): MutableList<UsbDevice>? {
return mUsbMonitor?.getDeviceList(arrayListOf<DeviceFilter>())?.let { devList ->
Logger.i(TAG, " find some device list, = $devList")
Expand Down
10 changes: 5 additions & 5 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
include ':app'

// For debug online
//include ':libausbc'
//include ':libuvc'
//include ':libpush'
//include ':libnative'
//include ':libuvccommon'
include ':libausbc'
include ':libuvc'
include ':libpush'
include ':libnative'
include ':libuvccommon'

0 comments on commit 31412b4

Please sign in to comment.