HUAWEI CaaS Kit Lite provides an open API based on the HUAWEI MeeTime service. It allows app and hardware developers to easily integrate video calling to their apps. With Huawei device virtualization technology, developers can define the video source themselves.
CaaS Kit Lite helps smart devices and apps implement system-level video calling, while constructing an accessible real-time communication network for optimal user experience.
In this codelab, you will create a demo project, integrate the CaaS Kit Lite SDK into the demo project, and complete the overall process setup of the CaaS Kit Lite service.
HUAWEI CaaS Kit Lite integration requires the following preparations:
For details, see CaaS Kit Lite Preparations.
Save the SDK package to the libs directory of the app and enter the following command in the build.gradle file of the app:
Change the value of minSdkVersion in the build.gradle file to 26, as shown in the following figure.
Click the sync button, as shown in the following figure.
After the synchronization, the screen shown in the following figure is displayed.
Add the app ID generated when creating the app on HUAWEI Developer to the AndroidManifest.xml file of the app. The name is com.huawei.hms.client.appid, and the value is appid=****. Replace ****** with the ID of your app.** For details about how to apply for permissions, see Permission Application in CaaS Kit Lite Preparations.
Broadcasts can be registered dynamically or statically. The following uses the dynamic registration as an example.
CaasKitHelper.java
public class CaasKitHelper {
private static CaasKitHelper mCaasKitHelper;
private DeviceDiscoverReceiver mDiscoverReceiver;
private HwCaasServiceManager mHwCaasServiceManager;
private HwCaasHandler mHwCaasHandler;
private HwCaasServiceCallBack mCallBack = new HwCaasServiceCallBack() {
@Override
public void initSuccess(HwCaasHandler handler) {
...
}
@Override
public void initFail(int retCode) {
...
}
@Override
public void releaseSuccess() {
...
}
};
private void registerDiscoverReceiver() {
Log.d(TAG, "registerDiscoverReceiver.");
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(DMSDP_STARTDISCOVERY);
if (mDiscoverReceiver == null) {
Log.d(TAG, "mDiscoverReceiver.");
mDiscoverReceiver = new DeviceDiscoverReceiver();
mContext.registerReceiver(mDiscoverReceiver, intentFilter);
}
}
public void caasKitInit() {
Log.d(TAG, "caasKitInit." + mIsCaasKitInit);
if (!mIsCaasKitInit) {
registerDiscoverReceiver();
/** Initialize mHwCaasServiceManager instance. */
mHwCaasServiceManager = HwCaasServiceManager.init();
/** Initialize HwCaasHandler instance through handlerType. */
mHwCaasServiceManager.initHandler(mContext, HwCaasUtils.VIRTUAL_CAMERA_TYPE, mCallBack);
mIsCaasKitInit = true;
}
}
...
}
The broadcast is as follows:
DeviceDiscoverReceiver.java
public class DeviceDiscoverReceiver extends BroadcastReceiver {
private static final String TAG = "DmsdpStartDiscoverReceiver";
private Context mApplicationContext;
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "DmsdpStartDiscoverReceiver.");
mApplicationContext = CaasKitApplication.getContext();
HwDmsdpService.init(mApplicationContext, new VirtualCameraListener());
}
}
Call CaasKitHelper.getInstance().caasKitInit() when appropriate to register the broadcast and initialize the CaaS service.
CaasKitDemoActivity.java
public class CaasKitDemoActivity extends AppCompatActivity {
...
@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume.");
if (mVideoView != null) {
mVideoView.onResume();
}
CaasKitHelper.getInstance().caasKitInit();
}
...
}
VirtualCameraListener.java
public class VirtualCameraListener extends CameraListener {
private static final String TAG = "VirtualCameraListener";
private static final int VIDEO_BUFFER_MODE_YUV = 1;
private static final int DEVICE_CAMERA = 5;
private static final String VIRCAMERA_NAME = "CaasKitCamera";
/**
* This ID is customized by the developer
*/
private static final String VIRCAMERA_ID = "virtualcamera0";
/**
* This ID is recommended to be generated by
* java.util.UUID.randomUUID().toString()
* please do not directly use the ID
* public static final String DEVICE_ID = "ff66bf58-6413-48e7-8dcd-c084254b199e";
* provided in the demo
*/
private String mDeviceID;
public VirtualCameraListener() {
mDeviceID = UUID.randomUUID().toString();
Log.d(TAG, "deviceID: " + mDeviceID);
}
@Override
public List<DeviceInfo> getDeviceInfo() {
Log.d(TAG, "getDeviceInfo.");
List<DeviceInfo> listDeviceInfo = new ArrayList<>();
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setDeviceID(mDeviceID);
deviceInfo.setDeviceName(VIRCAMERA_NAME);
deviceInfo.setDeviceType(DEVICE_CAMERA);
deviceInfo.properties.put(CommonUtils.DEVICE_SUPPORTCAMERA_BOOLEAN, "true");
listDeviceInfo.add(deviceInfo);
return listDeviceInfo;
}
@Override
public HashMap<String, CameraInfo> getCameraInfo(String deviceId) {
Log.d(TAG, "getCameraInfo." + deviceId);
HashMap<String, CameraInfo> mapCameraInfo = new HashMap<>();
CameraInfo cameraInfo = new CameraInfo();
cameraInfo.setCameraId(VIRCAMERA_ID);
cameraInfo.setVideoType(VIDEO_BUFFER_MODE_YUV);
cameraInfo.setSupportedFpsRange("25000,25000");
cameraInfo.setSupportedResolutionRange("1080,1920");
mapCameraInfo.put(VIRCAMERA_ID, cameraInfo);
return mapCameraInfo;
}
@Override
public CameraParameters getCameraParameters(String cameraId) {
Log.d(TAG, "getCameraParameters." + cameraId);
CameraParameters cameraParams = new CameraParameters();
cameraParams.cameraId = VIRCAMERA_ID;
cameraParams.properties.put(CommonUtils.CURRENT_RESOLUTION, "1080,1920");
cameraParams.properties.put(CommonUtils.CURRENT_FRAMERATES, "25000,30000");
cameraParams.properties.put(CommonUtils.CURRENT_IMAGEFORMAT, CommonUtils.IMAGE_FORMAT_NV21);
cameraParams.properties.put(CommonUtils.CURRENT_DECODEFORMAT, CommonUtils.DECODE_FORMAT_RGBA);
return cameraParams;
}
@Override
public int startCaptureVideo(String cameraId, Surface surface) {
Log.d(TAG, "startCaptureVideo." + cameraId);
if (ExtSurfaceRender.getInstance().isEGLContextReady()) {
Log.d(TAG, "startCaptureVideo.");
ExtSurfaceRender.getInstance().startRendering(surface);
}
return 0;
}
@Override
public int stopCaptureVideo(String cameraId) {
Log.d(TAG, "stopCaptureVideo.");
ExtSurfaceRender.getInstance().stopRendering();
return 0;
}
@Override
public int notifyUnbindMSDPService() {
Log.d(TAG, "notifyUnbindMSDPService.");
HwDmsdpService.release();
return 0;
}
@Override
public void checkPermissionOnCallback(int result) {
Log.d(TAG, "checkPermissionOnCallback.result: " + result);
}
}
CaasKitHelper.java
public class CaasKitHelper {
...
private static final String BACKGROUND_COLOR = "#FF4081";
private static final int VIEWHEIGHT = 248;
private static final int VIEWWIDTH = 256;
private static final int LOCATION_X = 102;
private static final int LOCATION_Y = 40;
private static final int LOCATION_STARTY = 24;
private HwCaasServiceCallBack mCallBack = new HwCaasServiceCallBack() {
@Override
public void initSuccess(HwCaasHandler handler) {
Log.i(TAG, ":HwCaasServiceCallBack:initSuccess");
/** Callback after successful initialization of HwCaasHandler. */
mHwCaasHandler = handler;
if (mHwCaasHandler != null) {
mHwCaasHandler.setContactViewSize(VIEWWIDTH, VIEWHEIGHT);
mHwCaasHandler.setAppMode(HwCaasUtils.LANDSCAPE);
mHwCaasHandler.setStartViewBackgroundColor(BACKGROUND_COLOR);
boolean isSetSuccess = false;
isSetSuccess = mHwCaasHandler.setFloatViewLocation(HwCaasUtils.STARTVIEW,
HwCaasUtils.POINT_RIGHTANDDOWN, LOCATION_X, LOCATION_STARTY);
Log.i(TAG, "viewType: " + HwCaasUtils.STARTVIEW + " isSetSuccess: " + isSetSuccess);
isSetSuccess = mHwCaasHandler.setFloatViewLocation(HwCaasUtils.CONTACTVIEW, HwCaasUtils.POINT_RIGHTANDUP, LOCATION_X, LOCATION_Y);
Log.i(TAG, "viewType: " + HwCaasUtils.CONTACTVIEW + " isSetSuccess: " + isSetSuccess);
isSetSuccess = mHwCaasHandler.setFloatViewLocation(HwCaasUtils.CALLVIEW, HwCaasUtils.POINT_RIGHTANDUP,
LOCATION_X, LOCATION_Y);
Log.i(TAG, "viewType: " + HwCaasUtils.CALLVIEW + " isSetSuccess: " + isSetSuccess);
isSetSuccess = mHwCaasHandler.setFloatViewLocation(HwCaasUtils.VIDEOVIEW, HwCaasUtils.POINT_RIGHTANDUP,
LOCATION_X, LOCATION_Y);
Log.i(TAG, "viewType: " + HwCaasUtils.VIDEOVIEW + " isSetSuccess: " + isSetSuccess);
if (mIsSendShowFail) {
sendShow();
mIsSendShowFail = false;
}
}
}
@Override
public void initFail(int retCode) {
/** Callback if init Handler fail. */
Log.i(TAG, "retCode: " + retCode);
}
@Override
public void releaseSuccess() {
Log.i(TAG, ":HwCaasServiceCallBack:releaseSuccess");
/** Callback after successful release of mHwCaasServiceManager. */
mHwCaasHandler = null;
}
};
...
}
CaasKitHelper.java
public class CaasKitHelper {
...
public boolean sendShow() {
Log.d(TAG, "sendShow.");
if (mHwCaasHandler != null) {
/** Send SHOW event to show suspension ball. */
boolean isSendoK = mHwCaasHandler.sendEventToCaasService(HwCaasUtils.SHOW);
Log.d(TAG, "isSendoK: " + isSendoK);
return isSendoK;
}
mIsSendShowFail = true;
Log.e(TAG, "sendShow fail.");
return false;
}
public boolean sendHide() {
Log.d(TAG, "sendHide.");
if (mHwCaasHandler != null) {
/** Send HIDE event to hide suspension ball. */
boolean isSendoK = mHwCaasHandler.sendEventToCaasService(HwCaasUtils.HIDE);
Log.d(TAG, "isSendoK: " + isSendoK);
return isSendoK;
}
Log.e(TAG, "sendHide fail.");
return false;
}
...
}
CaasKitHelper.java
public class CaasKitHelper {
...
public void caasKitRelease() {
Log.d(TAG, "caasKitRelease." + mIsCaasKitInit);
if (mIsCaasKitInit) {
if (mHwCaasServiceManager != null) {
/** Source release */
mHwCaasServiceManager.release();
mHwCaasServiceManager = null;
}
unregisterDiscoverReceiver();
mIsCaasKitInit = false;
}
}
...
}
You have successfully completed this CodeLab and learned:
For more information, please click the following link:
Document