Java 类org.webrtc.CameraEnumerator 实例源码

项目:matrix-android-sdk    文件:MXWebRtcCall.java   
/**
 * @return true if the device has a camera device
 */
private boolean hasCameraDevice() {
    CameraEnumerator enumerator = getCameraEnumerator(mContext);
    String[] deviceNames = enumerator.getDeviceNames();
    int cameraCount = 0;

    mBackCameraName = mFrontCameraName = null;

    if (null != deviceNames) {
        for (String deviceName : deviceNames) {
            if (enumerator.isFrontFacing(deviceName) && !isCameraInUse(mContext, true)) {
                mFrontCameraName = deviceName;
            } else if (enumerator.isBackFacing(deviceName) && !isCameraInUse(mContext, false)) {
                mBackCameraName = deviceName;
            }
        }

        cameraCount = deviceNames.length;
    }

    Log.d(LOG_TAG, "hasCameraDevice():  camera number= " + cameraCount);
    Log.d(LOG_TAG, "hasCameraDevice():  frontCameraName=" + mFrontCameraName + " backCameraName=" + mBackCameraName);

    return (null != mFrontCameraName) || (null != mBackCameraName);
}
项目:matrix-android-sdk    文件:MXWebRtcCall.java   
/**
 * Create the video capturer
 *
 * @param cameraName the selected camera name
 * @return the video capturer
 */
private CameraVideoCapturer createVideoCapturer(String cameraName) {
    CameraVideoCapturer cameraVideoCapturer = null;

    CameraEnumerator camerasEnumerator = getCameraEnumerator(mContext);
    final String[] deviceNames = camerasEnumerator.getDeviceNames();


    if ((null != deviceNames) && (deviceNames.length > 0)) {
        for (String name : deviceNames) {
            if (name.equals(cameraName)) {
                cameraVideoCapturer = camerasEnumerator.createCapturer(name, null);
                if (null != cameraVideoCapturer) {
                    break;
                }
            }
        }

        if (null == cameraVideoCapturer) {
            cameraVideoCapturer = camerasEnumerator.createCapturer(deviceNames[0], null);
        }
    }

    return cameraVideoCapturer;
}
项目:matrix-android-sdk    文件:MXWebRtcCall.java   
/**
 * Get a camera enumerator
 *
 * @param context the context
 * @return the camera enumerator
 */
private static CameraEnumerator getCameraEnumerator(Context context) {
    if (useCamera2(context)) {
        return new Camera2Enumerator(context);
    } else {
        return new Camera1Enumerator(false);
    }
}