Cloud Storage

Last Updated on : 2024-04-16 07:53:33download

IP cameras (IPCs) support the cloud storage service that allows users to save video footage on the IPCs to the cloud.

How it works

  1. Determine whether a device supports cloud storage. If this service is supported, proceed with the process.
  2. Get the cloud storage service status.
  3. Perform steps based on the service status:
    • If the cloud storage service is inactivated or has expired, this service must be purchased to enable cloud storage.

      After the cloud storage service expires, the existing cloud-stored video files will be retained for a period, seven days in most cases. At the end of this period, all cloud-stored video files will be deleted.

    • If the cloud storage service is within the validity period:

      1. Get the date on which the cloud-stored video files were created.
      2. Get the data of the specified date, including cloud storage events, timeline data, and authentication information.
      3. Select a cloud storage event or a time point to start cloud-stored video playback.
      Cloud Storage

Support for cloud storage

IThingIPCCloud provides a collection of cloud storage APIs, including the one used to check the support for cloud storage capabilities.

API description

boolean isSupportCloudStorage(String devId);

Parameters

Parameter Description
devId The device ID.

Example

IThingIPCCloud cloud = ThingIPCSdk.getCloud();
    if (cloud != null) {
    isSupportCloudStorage = cloud.isSupportCloudStorage(devId);
    }

Subscription

To enable subscription to the cloud storage service, the Cloud Storage UI BizBundle must be integrated. This component provides the H5 pages and order display features for the subscription.

Cloud storage object

IThingCloudCamera provides API methods to deal with cloud-stored video footage.

API description

Create a cloud storage instance object.

Some IThingCloudCamera APIs are implemented asynchronously. It is recommended not to call other methods of an object within this object’s callback, as it may cause Application Not Responding (ANR) issues.

IThingCloudCamera createCloudCamera();

Example

private IThingCloudCamera cloudCamera;

        IThingIPCCloud cloud = ThingIPCSdk.getCloud();
        if (cloud != null) {
        cloudCamera = cloud.createCloudCamera();
        }

Generic cloud storage

Get the status of cloud storage subscription

API description

void queryCloudServiceStatus(String devId, IThingResultCallback<CloudStatusBean> callback);

Parameters

Parameter Description
devId The device ID.
callback The callback.

Example

cloudCamera.queryCloudServiceStatus(devId, new IThingResultCallback<CloudStatusBean>() {
@Override
public void onSuccess(CloudStatusBean result) {
        //Get cloud storage status
        }

@Override
public void onError(String errorCode, String errorMessage) {

        }
        });

Data model of CloudStatusBean

Parameter Description
status The status code.
  • 10001: The cloud storage service is not purchased.
  • 10010: The cloud storage service has already been activated.
  • 10011: The cloud storage service has expired.

Query cloud-stored video date

API description

void getCloudDays(String devId, String timezoneId, IThingResultCallback<List<CloudDayBean>> callback);

Parameters

Parameter Description
devId The device ID.
timezoneId The time zone ID.

Example

cloudCamera.getCloudDays(devId, TimeZone.getDefault().getID(), new IThingResultCallback<List<CloudDayBean>>() {
@Override
public void onSuccess(List<CloudDayBean> result) {

        }

@Override
public void onError(String errorCode, String errorMessage) {

        }
        });

Data model of CloudDayBean

Parameter Description
uploadDay The date.
currentDayStart The start time of a period in which video clips are returned.
currentDayEnd The end time of a period in which video clips are returned.

Query video clips within a specified period

API description

void getTimeLineInfo(String devId, long timeGT, long timeLT, IThingResultCallback<List<TimePieceBean>> callback);

Parameters

Parameter Description
devId The device ID.
timeGT The 10-digit start timestamp.
timeLT The 10-digit end timestamp.
callback The callback.

Example

CloudDayBean dayBean = dayBeanList.get(0);
        cloudCamera.getTimeLineInfo(devId, dayBean.getCurrentStartDayTime(), dayBean.getCurrentDayEndTime(), new IThingResultCallback<List<TimePieceBean>>() {
@Override
public void onSuccess(List<TimePieceBean> result) {

        }

@Override
public void onError(String errorCode, String errorMessage) {

        }
        });

Data model of AITimePieceBean

Parameter Description
startTime The start Unix timestamp of the video clip.
endTime The end Unix timestamp of the video clip.
aiCode The ID of the AI event clip.

Query motion detection data within a specified period

API description

void getMotionDetectionInfo(String devId, long timeGT, long timeLT, int offset, int limit, IThingResultCallback<List<TimeRangeBean>> callback);

Parameters

Parameter Description
devId The device ID.
timeGT The 10-digit start timestamp.
timeLT The 10-digit end timestamp.
offset The page number starting from which target data is returned. Default value: 0.
limit The maximum number of entries to be returned at a time. Default value: -1 to return all data.
callback The callback.

Data model of TimeRangeBean

Parameter Description
describe The description of motion detection.
startTime The time when the motion detection event started.
endTime The time when the motion detection event ended.
snapshotUrl The image of the motion detection event.
v The version. A value of 2 indicates that the image is encrypted.

Example

CloudDayBean dayBean = dayBeanList.get(0);
        cloudCamera.getMotionDetectionInfo(devId, dayBean.getCurrentStartDayTime(), dayBean.getCurrentDayEndTime(), offset, limit, new IThingResultCallback<List<TimeRangeBean>>() {
@Override
public void onSuccess(List<TimeRangeBean> result) {

        }

@Override
public void onError(String errorCode, String errorMessage) {

        }
        });

The screenshots of cloud storage events are encrypted before they can be displayed by the image encryption component. For more information, see Encrypted Images.

Get key for cloud storage

API description

 void getCloudSecret(String devId, ResultListener<JSONObject> callback)

Parameters

Parameter Description
devId The device ID.
Business.ResultListener The callback.

Example

CloudBusiness cloudBusiness =new CloudBusiness();
    cloudBusiness.getCloudSecret(devId, new Business.ResultListener<JSONObject>() {
            @Override
            public void onFailure(BusinessResponse bizResponse, JSONObject bizResult, String apiName) {

            }

            @Override
            public void onSuccess(BusinessResponse bizResponse, JSONObject bizResult, String apiName) {
                    mEncryptKey = bizResult.getString("encryptKey");
            }
        });

Error codes

Error code Description
-2000 Failed to save the information about the cloud-stored video clips.
-2001 The authentication information for cloud storage is empty.
-2002 Failed to parse the URL for playing cloud-stored resources.

AI-based cloud storage

Query AI-based cloud storage settings on device

Check whether AI-based detection is enabled for a specific device.

API description

void queryAIDetectConfig(String devId, IThingResultCallback<AIDetectConfigBean> callback);

Data model of AIDetectConfigBean

Parameter Description
switchState Indicates whether AI-based detection is enabled for the device.
  • 1: Enabled
  • 0: Disabled
isAiDevice Indicates whether the device supports AI-based detection.
aiItemList The data of objects supported by AI-based detection.

Data model of AIDetectEventBean

Parameter Description
aiCode The identifier of an AI model.
aiCodeIcon The icon of an AI model.
aiCodeDesc The description of an AI model.
configState Indicates whether the current model is enabled.
  • 1: Enabled
  • 0: Disabled
orderValue The sorting value of the current model.

Example

cloudCamera.queryAIDetectConfig(getDevId(), new IThingResultCallback<AIDetectConfigBean>() {
            @Override
            public void onSuccess(AIDetectConfigBean result) {
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
            }
        });

Update on/off status of AI-based detection

Enable or disable AI-enabled detection for a specific device.

API description

void enableAIDetect(String devId, boolean enable, IThingResultCallback<Boolean> callback);

Parameters

Parameter Description
devId The device ID.
enable Specifies whether to enable or disable AI-enabled detection.

Example

cloudCamera.enableAIDetect(getDevId(), enable, new IThingResultCallback<AIDetectConfigBean>() {
            @Override
            public void onSuccess(Boolean result) {
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
            }
        });

Update AI-based detection type

API description

void enableAIDetectEventType(String devId, String aiCode, int enableState, IThingResultCallback<Boolean> callback);

Parameters

Parameter Description
devId The device ID.
aiCode The ID of an AI event.
enableState Specifies whether AI-based detection is enabled.
  • 0: Disabled
  • 1: Enabled

Example

cloudCamera.enableAIDetectEventType(getDevId(), aiCode, enableState, new IThingResultCallback<AIDetectConfigBean>() {
            @Override
            public void onSuccess(Boolean result) {
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
            }
        });

Query AI-based cloud storage events

After AI-based cloud storage is enabled, the device can report events when detection alerts are triggered. AI-based algorithms can be used to accurately identify whether the reported events include the objects specified by users. Currently, the supported objects include humans, pets, vehicles, and packages.

Alert events and detection messages for AI-based cloud storage are handled with the same logic as that for generic cloud storage.

API description

void getMotionDetectionInfo(String devId, String aiCodes, long timeGT, long timeLT, int offset, int limit, IThingResultCallback<List<TimeRangeBean>> callback);

Parameters

Parameter Description
devId The device ID.
aiCodes The list of AI event IDs, for example, ai_package,ai_human.
timeGT The 10-digit start timestamp.
timeLT The 10-digit end timestamp.
offset The page number starting from which target data is returned. Default value: 0.
limit The maximum number of entries to be returned at a time. Default value: -1 to return all data.
callback The callback.

Cloud storage management

Initialization

Create a device object.

API description

void createCloudDevice(String cachePath, String devId)

Parameters

Parameter Description
cachePath The path of the cache.
devId The device ID.

Example

cloudCamera.createCloudDevice(cachePath, devId);

Deinitialization

API description

void deinitCloudCamera();

Example

cloudCamera.deinitCloudCamera();

Destroy

API description

public void destroy();

Example

cloudCamera.destroy();

Register a cloud storage listener

Register a listener with IThingCloudCamera. Otherwise, video images cannot be displayed as expected.

API description

void registorOnP2PCameraListener(OnP2PCameraListener listener);

Parameters

Parameter Description
listener The P2P connection callback.

Example

cloudCamera.registorOnP2PCameraListener(new AbsP2pCameraListener() {
@Override
public void onSessionStatusChanged(Object camera, int sessionId, int sessionStatus) {
        super.onSessionStatusChanged(camera, sessionId, sessionStatus);
        }
        });

Unregister a cloud storage listener

API description

void removeOnP2PCameraListener();

Example

cloudCamera.removeOnP2PCameraListener();

Bind a playback component view

API description

void generateCloudCameraView(IRegistorIOTCListener view);

Parameters

Parameter Description
view The player component.

Example

cloudCamera.generateCloudCameraView(mVideoView);

Cloud storage usage

Start playback

API description

The start time mStartTime must be within the timeframe returned by getTimeLineInfo.

void playCloudDataWithStartTime(long mStartTime, long mEndTime, boolean isEvent, OperationCallBack callback, OperationCallBack playFinishedCallBack);

Parameters

Parameter Description
mStartTime The 10-digit start timestamp.
mEndTime The end timestamp of the period in which video clips are played back. By default, it is the end timestamp of the current day.
isEvent Indicates whether this is a detection event.
  • true: Play from the actual start time of the event (≤ mStartTime).
  • false (default): Play from the mStartTime.
callBack The playback callback.
playFinishedCallBack The playback completion callback.

Example

cloudCamera.playCloudDataWithStartTime(startTime, endTime, isEvent,
        new OperationCallBack() {
@Override
public void onSuccess(int sessionId, int requestId, String data, Object camera) {
        // The callback to be invoked when video clips are being played back. `playing` is returned.
        }

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

        }
        }, new OperationCallBack() {
@Override
public void onSuccess(int sessionId, int requestId, String data, Object camera) {
        // The callback to be invoked when playback is ended. `playCompleted` is returned.
        }

@Override
public void onFailure(int sessionId, int requestId, int errCode, Object camera) {
        }
        });

Pause playback

API description

int pausePlayCloudVideo(OperationDelegateCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Example

cloudCamera.pausePlayCloudVideo(new OperationDelegateCallBack() {
@Override
public void onSuccess(int sessionId, int requestId, String data) {
        }

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

        }
        });

Resume playback

API description

int resumePlayCloudVideo(OperationDelegateCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Example

cloudCamera.resumePlayCloudVideo(new OperationDelegateCallBack() {
@Override
public void onSuccess(int sessionId, int requestId, String data) {
        }

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

        }
        });

Stop playback

API description

int stopPlayCloudVideo(OperationDelegateCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Example

cloudCamera.stopPlayCloudVideo(new OperationDelegateCallBack() {
@Override
public void onSuccess(int sessionId, int requestId, String data) {
        }

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

        }
        });

Download cloud-stored video clips

API description

void startCloudDataDownload(long startTime, long stopTime, String folderPath, String mp4FileName,
        OperationCallBack callback, ProgressCallBack progressCallBack, OperationCallBack finishedCallBack);

Parameters

Parameter Description
startTime The 10-digit start timestamp of the video clip to be downloaded.
stopTime The 10-digit end timestamp of the video clip to be downloaded.
folderPath The path where the video clips are stored.
mp4FileName The name of the target video file.
callback The callback.
progressCallBack The callback for the download progress.
finishedCallBack The download completion callback.

Stop video download

API description

void stopCloudDataDownload(OperationCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Delete cloud-stored video clips

API description

void deleteCloudVideo(String devId, long timeGT, long timeLT, boolean isAllDay, String timeZone, IThingResultCallback<String> listener);

Parameters

Parameter Description
devId The device ID.
timeGT The 10-digit start timestamp.
timeLT The end date and time.
isAllDay Specifies whether to delete the data for the whole day.
timeZone The time zone.
listener The callback.

Video recording

Start video recording

API description

int startRecordLocalMp4(String folderPath, String fileName, OperationDelegateCallBack callBack);

Parameters

Parameter Description
folderPath The directory in which the video file is stored.
fileName The name of the video file.
callBack The callback.

Example

cloudCamera.startRecordLocalMp4(IPCCameraUtils.recordPath(devId), String.valueOf(System.currentTimeMillis()), new OperationDelegateCallBack() {
@Override
public void onSuccess(int sessionId, int requestId, String data) {
        Toast.makeText(CameraCloudStorageActivity.this, "record start success", Toast.LENGTH_SHORT).show();
        }

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

Stop video recording

API description

int stopRecordLocalMp4(OperationDelegateCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Example

cloudCamera.stopRecordLocalMp4(new OperationDelegateCallBack() {
@Override
public void onSuccess(int sessionId, int requestId, String data) {
        Toast.makeText(CameraCloudStorageActivity.this, "record end success", Toast.LENGTH_SHORT).show();
        }

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

Additional features

Cloud-stored video playback supports additional features, such as the audio switch and screenshots.

Get mute status

API description

int getCloudMute();

Example

cloudCamera.getCloudMute()

Set mute status

API description

void setCloudMute(final int mute, OperationDelegateCallBack callBack);

Parameters

Parameter Description
mute Specify whether to mute the video.
  • 1: Mute
  • 0: Unmute
callBack The callback.

Example

cloudCamera.setCloudMute(mute, new OperationDelegateCallBack() {
@Override
public void onSuccess(int sessionId, int requestId, String data) {
        soundState = Integer.valueOf(data);
        }

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

Take video screenshots

API description

int snapshot(String absoluteFilePath, OperationDelegateCallBack callBack);

Parameters

Parameter Description
absoluteFilePath The URL of the screenshot file.
callBack The callback.

Example

cloudCamera.snapshot(IPCCameraUtils.recordSnapshotPath(devId), new OperationDelegateCallBack() {
@Override
public void onSuccess(int sessionId, int requestId, String data) {
        Toast.makeText(CameraCloudStorageActivity.this, "snapshot success", Toast.LENGTH_SHORT).show();
        }

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

Set playback speed

Set the playback speed after video playing is started. Audio playback does not support the playback speed setting.

API description

void setPlayCloudDataSpeed(int speed, OperationCallBack operationCallBack);

Parameters

Parameter Description
speed The playback speed that supports 1x, 2x, and 4x. You can get an enum value of CloudPlaySpeed to set the playback speed.
operationCallBack The callback.

Enum values of CloudPlaySpeed

        CloudPlaySpeed.MULTIPLE_1,               // 1.0x
        CloudPlaySpeed.MULTIPLE_2,               // 2.0x
        CloudPlaySpeed.MULTIPLE_4,               // 4.0x

Example

 mCloudCamera.setPlayCloudDataSpeed(speed, new OperationCallBack() {
@Override
public void onSuccess(int sessionId, int requestId, String data, Object camera) {
        // TODO " setPlayCloudDataSpeed onSuccess"
        }

@Override
public void onFailure(int sessionId, int requestId, int errCode, Object camera) {
        }
        });