1. Camera functions

IPC SDK provides live video of smart cameras, device memory card video playback, screenshots, recorded videos, and real-time calls with cameras. It also provides YUV data after video frame decoding. Developers can Perform secondary processing on the video data.

1.1. Live Video

For live video, you need to create an ITuyaSmartCameraP2P object, and then make a P2P connection to play the live video, Screenshots, recorded videos, and real-time intercom data transfers.

1.1.1. init

create ITuyaSmartCameraP2P object

Declaration

public static ITuyaSmartCameraP2P createCameraP2P(int p2pType, String devId);

Parameter

Parameter Description
p2pType device type. Obtained from DeviceBean, see P2p Type

Example

ITuyaSmartCameraP2P cameraP2P = TuyaSmartCameraP2PFactory.createCameraP2P(intentP2pType, devId);

use TuyaCameraView in XML layout

TuyaCameraView is a video rendering view provided by the IPC SDK. If you need to use your own video rendering view, you only need to implement the IRegistorIOTCListener interface, and then bind your own video rendering view to ITuyaSmartCameraP2P.

Example

<com.tuya.smart.camera.middleware.widget.TuyaCameraView
  android:id="@+id/camera_video_view"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  />

Set callback for TuyaCameraView

Declaration

public void setViewCallback(AbsVideoViewCallback callback);

Parameter

Parameter Description
callback Callback interface

Example

TuyaCameraView mVideoView = findViewById(R.id.camera_video_view);
mVideoView.setViewCallback(new AbsVideoViewCallback() {
    @Override
    public void onCreated(Object o) {
        super.onCreated(o);
        //Callback when render view construction is completed
    }
});

AbsVideoViewCallback

callback of TuyaCameraView, developers only need to overwrite the callbacks they care about, and generally only need to overwrite the ʻonCreated` method.

Declaration

callback when TuyaCameraView is ready to render view

public void onCreated(Object view);

Declaration

callback when click on the view

public void videoViewClick();

Declaration

callback when scroll on the view

public void startCameraMove(String cameraDirection)

Parameter

Parameter Description
cameraDirection direction. "0" means up,"2" means right,"4" means down,"6" means left

Parameter

callback when action up

public void onActionUP()

Create render view

Declaration

public void createVideoView(int p2pType);

Parameters

Parameter Description
p2pType device type. Obtained from DeviceBean, see P2p Type

Example

TuyaCameraView mVideoView = findViewById(R.id.camera_video_view);
mVideoView.createVideoView(p2pType);

Declaration

Get render view

if the render view is not constructed, will return null

public Object createdView();

Example

TuyaCameraView mVideoView = findViewById(R.id.camera_video_view);
mVideoView.createdView()

Bind the render view for ITuyaSmartCameraP2P

Declaration

void generateCameraView(T view);

Example

mCameraP2P.generateCameraView(mVideoView.createdView());

register listener

register a listener with ITuyaSmartCameraP2P, Developers only need to overwrite the callbacks you care about

Declaration

void registerP2PCameraListener(AbsP2pCameraListener listener);

Example

// 1. create ITuyaSmartCameraP2P object
ITuyaSmartCameraP2P mCameraP2P = TuyaSmartCameraP2PFactory.createCameraP2P(p2pType, devId);
TuyaCameraView mVideoView = findViewById(R.id.camera_video_view);
// 2. set callback for TuyaCameraView
mVideoView.setViewCallback(new AbsVideoViewCallback() {
    @Override
    public void onCreated(Object o) {
        super.onCreated(o);
        //4. when render view construction is completed, bind render view for ITuyaSmartCameraP2P
        if (null != mCameraP2P){
            mCameraP2P.generateCameraView(o);
        }
    }
});
// 3. create render view
mVideoView.createVideoView(p2pType);
// 4. register P2P listener
mCameraP2P.registerP2PCameraListener(new AbsP2pCameraListener() {
    @Override
    public void onSessionStatusChanged(Object o, int i, int i1) {
        super.onSessionStatusChanged(o, i, i1);
    }
});

1.1.2. P2P connection

Before starting video playback, you need to connect the P2P channel. The P2P status needs to be maintained by the user. The SDK is only responsible for issuing instructions and receiving camera response results.

Declaration

connect P2P

void connect(String devId, OperationDelegateCallBack callBack);

dsiconnect P2P

void disconnect(String devId, OperationDelegateCallBack callBack);

Parameter

Parameter Description
callBack result callback

Example

mCameraP2P.connect(devId, new OperationDelegateCallBack() {
    @Override
    public void onSuccess(int sessionId, int requestId, String data) {

    }

    @Override
    public void onFailure(int sessionId, int requestId, int errCode) {

    }
});

1.1.3. Live video

After the p2p channel is successfully connected, you can start playing live video.

Declaration

Start playing live video.

void startPreview(int clarity, OperationDelegateCallBack callBack);

Stop playing live video.

int stopPreview(OperationDelegateCallBack callBack);

Parameter

Parameter Description
clarity sharpness
callBack result callback

Clarity model

mode value
SD 2
HD 4

Example

mCameraP2P.startPreview(new OperationDelegateCallBack() {
    @Override
    public void onSuccess(int sessionId, int requestId, String data) {

    }

    @Override
    public void onFailure(int sessionId, int requestId, int errCode) {

    }
});

Note: After the startPreview callback is successful, the onReceiveFrameYUVData callback will start receiving video data and throw it to the business layer.

1.1.4. Destroy ITuyaSmartCameraP2P

Destroy the object, when you no longer use the camera function, you must remove P2P listener and call destroy

Declaration

remove P2P lisetner

void removeOnP2PCameraListener();

Declaration

destroy camera object

void destroyP2P();

Example

if (null != mTuyaSmartCamera) {
    mTuyaSmartCamera.removeOnP2PCameraListener();
    mTuyaSmartCamera.destroyP2P();
}

1.2. Flow chart

results matching ""

    No results matching ""