Java源码示例:com.serenegiant.usb.USBMonitor.UsbControlBlock
示例1
private final String getUSBFSName(final UsbControlBlock ctrlBlock) {
String result = null;
final String name = ctrlBlock.getDeviceName();
final String[] v = !TextUtils.isEmpty(name) ? name.split("/") : null;
if ((v != null) && (v.length > 2)) {
final StringBuilder sb = new StringBuilder(v[0]);
for (int i = 1; i < v.length - 2; i++)
sb.append("/").append(v[i]);
result = sb.toString();
}
if (TextUtils.isEmpty(result)) {
Log.w(TAG, "failed to get USBFS path, try to use default path:" + name);
result = DEFAULT_USBFS;
}
return result;
}
示例2
@Override
public void onConnect(final UsbDevice device, final UsbControlBlock ctrlBlock, final boolean createNew) {
if (DEBUG) Log.d(TAG, "OnDeviceConnectListener#onConnect:");
final int key = device.hashCode();
CameraServer service;
synchronized (sServiceSync) {
service = sCameraServers.get(key);
if (service == null) {
service = CameraServer.createServer(UVCService.this, ctrlBlock, device.getVendorId(), device.getProductId());
sCameraServers.append(key, service);
} else {
Log.w(TAG, "service already exist before connection");
}
sServiceSync.notifyAll();
}
}
示例3
private final String getUSBFSName(final UsbControlBlock ctrlBlock) {
String result = null;
final String name = ctrlBlock.getDeviceName();
final String[] v = !TextUtils.isEmpty(name) ? name.split("/") : null;
if ((v != null) && (v.length > 2)) {
final StringBuilder sb = new StringBuilder(v[0]);
for (int i = 1; i < v.length - 2; i++)
sb.append("/").append(v[i]);
result = sb.toString();
}
if (TextUtils.isEmpty(result)) {
Log.w(TAG, "failed to get USBFS path, try to use default path:" + name);
result = DEFAULT_USBFS;
}
return result;
}
示例4
/**
* connect to a UVC camera
* USB permission is necessary before this method is called
* @param ctrlBlock
*/
public synchronized void open(final UsbControlBlock ctrlBlock) {
int result;
try {
mCtrlBlock = ctrlBlock.clone();
result = nativeConnect(mNativePtr,
mCtrlBlock.getVenderId(), mCtrlBlock.getProductId(),
mCtrlBlock.getFileDescriptor(),
mCtrlBlock.getBusNum(),
mCtrlBlock.getDevNum(),
getUSBFSName(mCtrlBlock));
} catch (final Exception e) {
Log.w(TAG, e);
result = -1;
}
if (result != 0) {
throw new UnsupportedOperationException("open failed:result=" + result);
}
if (mNativePtr != 0 && TextUtils.isEmpty(mSupportedSize)) {
mSupportedSize = nativeGetSupportedSize(mNativePtr);
}
nativeSetPreviewSize(mNativePtr, DEFAULT_PREVIEW_WIDTH, DEFAULT_PREVIEW_HEIGHT,
DEFAULT_PREVIEW_MIN_FPS, DEFAULT_PREVIEW_MAX_FPS, DEFAULT_PREVIEW_MODE, DEFAULT_BANDWIDTH);
}
示例5
private final String getUSBFSName(final UsbControlBlock ctrlBlock) {
String result = null;
final String name = ctrlBlock.getDeviceName();
final String[] v = !TextUtils.isEmpty(name) ? name.split("/") : null;
if ((v != null) && (v.length > 2)) {
final StringBuilder sb = new StringBuilder(v[0]);
for (int i = 1; i < v.length - 2; i++)
sb.append("/").append(v[i]);
result = sb.toString();
}
if (TextUtils.isEmpty(result)) {
Log.w(TAG, "failed to get USBFS path, try to use default path:" + name);
result = DEFAULT_USBFS;
}
return result;
}
示例6
/**
* connect to a UVC camera
* USB permission is necessary before this method is called
* @param ctrlBlock
*/
public synchronized void open(final UsbControlBlock ctrlBlock) {
int result = -2;
StringBuilder sb = new StringBuilder();
try {
mCtrlBlock = ctrlBlock.clone();
result = nativeConnect(mNativePtr,
mCtrlBlock.getVenderId(), mCtrlBlock.getProductId(),
mCtrlBlock.getFileDescriptor(),
mCtrlBlock.getBusNum(),
mCtrlBlock.getDevNum(),
getUSBFSName(mCtrlBlock));
sb.append("调用nativeConnect返回值:"+result);
// long id_camera, int venderId, int productId, int fileDescriptor, int busNum, int devAddr, String usbfs
} catch (final Exception e) {
Log.w(TAG, e);
for(int i = 0; i< e.getStackTrace().length; i++){
sb.append(e.getStackTrace()[i].toString());
sb.append("\n");
}
sb.append("core message ->"+e.getLocalizedMessage());
result = -1;
}
if (result != 0) {
throw new UnsupportedOperationException("open failed:result=" + result+"----->" +
"id_camera="+mNativePtr+";venderId="+mCtrlBlock.getVenderId()
+";productId="+mCtrlBlock.getProductId()+";fileDescriptor="+mCtrlBlock.getFileDescriptor()
+";busNum="+mCtrlBlock.getBusNum()+";devAddr="+mCtrlBlock.getDevNum()
+";usbfs="+getUSBFSName(mCtrlBlock)+"\n"+"Exception:"+sb.toString());
}
if (mNativePtr != 0 && TextUtils.isEmpty(mSupportedSize)) {
mSupportedSize = nativeGetSupportedSize(mNativePtr);
}
nativeSetPreviewSize(mNativePtr, DEFAULT_PREVIEW_WIDTH, DEFAULT_PREVIEW_HEIGHT,
DEFAULT_PREVIEW_MIN_FPS, DEFAULT_PREVIEW_MAX_FPS, DEFAULT_PREVIEW_MODE, DEFAULT_BANDWIDTH);
}
示例7
private CameraThread(final Context context, final UsbControlBlock ctrlBlock) {
super("CameraThread");
if (DEBUG) Log.d(TAG_THREAD, "Constructor:");
mWeakContext = new WeakReference<Context>(context);
mCtrlBlock = ctrlBlock;
loadSutterSound(context);
}
示例8
/**
* connect to a UVC camera
* USB permission is necessary before this method is called
* @param ctrlBlock
*/
public void open(final UsbControlBlock ctrlBlock) {
mCtrlBlock = ctrlBlock;
nativeConnect(mNativePtr,
mCtrlBlock.getVenderId(), mCtrlBlock.getProductId(),
mCtrlBlock.getFileDescriptor(),
getUSBFSName(mCtrlBlock));
if (mNativePtr != 0 && TextUtils.isEmpty(mSupportedSize)) {
mSupportedSize = nativeGetSupportedSize(mNativePtr);
}
nativeSetPreviewSize(mNativePtr, DEFAULT_PREVIEW_WIDTH, DEFAULT_PREVIEW_HEIGHT,
DEFAULT_PREVIEW_MIN_FPS, DEFAULT_PREVIEW_MAX_FPS, DEFAULT_PREVIEW_MODE, DEFAULT_BANDWIDTH);
}
示例9
public UsbControlBlock getUsbControlBlock() {
return mCtrlBlock;
}
示例10
@Override
public void onConnect(final UsbDevice device, final UsbControlBlock ctrlBlock, final boolean createNew) {
if (DEBUG) Log.v(TAG, "OnDeviceConnectListener#onConnect:");
}
示例11
@Override
public void onDisconnect(final UsbDevice device, final UsbControlBlock ctrlBlock) {
if (DEBUG) Log.v(TAG, "OnDeviceConnectListener#onDisconnect:");
}
示例12
@Override
public void onDisconnect(final UsbDevice device, final UsbControlBlock ctrlBlock) {
if (DEBUG) Log.d(TAG, "OnDeviceConnectListener#onDisconnect:");
removeService(device);
}
示例13
public static CameraServer createServer(final Context context, final UsbControlBlock ctrlBlock, final int vid, final int pid) {
if (DEBUG) Log.d(TAG, "createServer:");
final CameraThread thread = new CameraThread(context, ctrlBlock);
thread.start();
return thread.getHandler();
}
示例14
public UsbControlBlock getUsbControlBlock() {
return mCtrlBlock;
}
示例15
public UsbControlBlock getUsbControlBlock() {
return mCtrlBlock;
}