Last Updated on : 2023-05-22 06:38:31download
Cloud storage can be implemented for IP cameras (IPCs), so users can save video footage on the IPCs to the cloud.
First, get the cloud storage service status. If the cloud storage service is unactivated or has expired and all cloud-stored video files have been deleted, the cloud storage service must be purchased to enable the cloud storage service. After the cloud storage service expires, the existing cloud-stored video files will be retained for a period, seven days in most cases.
If the cloud storage service is within the validity period, get the date when the cloud-stored video files were created, and get the data of the specified date, including cloud storage events, timeline data, and authentication information. Then, a cloud storage event or a time point can be selected to start cloud-stored video playback.
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.
After the subscription to the cloud storage service, users can upload video footage on an IPC to the cloud. Then, they can view and play back cloud-stored video footage based on the IPC SDK. Cloud storage is implemented with the class TuyaSmartCloudManager
in TuyaSmartCameraKit
.
Classes and protocols
Class name (protocol name) | Description |
---|---|
TuyaSmartCloudManager | Cloud storage service status, video maintenance, and cloud-stored video playback |
TuyaSmartCloudManagerDelegate | Cloud-stored video playback, callback delegate for video frames |
API description
To initialize TuyaSmartCloudManager
, pass in the device ID.
Cloud-stored video footage is played back in mute mode by default. To enable the audio mode for playback, you can set the mute state to NO
during initialization. The IPC delegate provides the callback to return information about video frames and headers during playback.
- (instancetype)initWithDeviceId:(NSString *)devId;
Parameters
Parameter | Description |
---|---|
devId | The device ID. |
You can set the image encryption state to YES
, so the images in cloud storage events will be encrypted. In this case, the component TYEncryptImage
is used to display images.
API description
@property (nonatomic, assign) BOOL enableEncryptedImage;
The cloud storage delegate TuyaSmartCloudManagerDelegate
provides only one delegate method to return YUV data and frame data of each video frame. You can render video images with your own method. For this purpose, set the autoRender
property of TuyaSmartCloudManager
to NO
(default value: YES
), and implement the delegate method to get YUV data of video frames. This way, the IPC SDK does not automatically render video images.
API description
- (void)cloudManager:(TuyaSmartCloudManager *)cloudManager didReceivedFrame:(CMSampleBufferRef)frameBuffer videoFrameInfo:(TuyaSmartVideoFrameInfo)frameInfo;
Parameters
Parameter | Description |
---|---|
cloudManager | The object TuyaSmartCloudManager to play back cloud-stored video footage. |
frameBuffer | The YUV data of video frames. |
frameInfo | The information about video frames. |
Before cloud-stored video playback, cloud storage data must be loaded. The returned cloud storage data include the current status of the cloud storage service, encryption key, authentication information, and more.
API description
- (void)loadCloudData:(void(^)(TuyaSmartCloudState state))complete
Parameters
Parameter | Description |
---|---|
complete | The success callback. The current cloud storage service status is returned. |
Enum values of TuyaSmartCloudState
Enum value | Description |
---|---|
TuyaSmartCloudStateNoService | The cloud storage service is not activated. |
TuyaSmartCloudStateNoData | The cloud storage service is activated, but no video is available for playback. |
TuyaSmartCloudStateValidData | The cloud storage service is activated and videos are available for playback. |
TuyaSmartCloudStateExpiredNoData | The cloud storage service has expired and no video is available for playback. |
TuyaSmartCloudStateExpiredData | The cloud storage service has expired, but videos are still available for playback. |
TuyaSmartCloudStateLoadFailed | Failed to load cloud storage service status |
After the cloud storage service expires, the existing cloud-stored video files will be retained for a period, seven days in most cases. This retention period is subject to the cloud storage service agreement. If the subscription is not renewed within this period, the cloud-stored video footage will be deleted at the end of this period.
After the cloud storage data is returned, if cloud-stored video footage can be played back, the cloudDays
property indicates the date on which cloud-stored video footage can be played back.
API description
@property (nonatomic, strong, readonly) NSArray<TuyaSmartCloudDayModel *> *cloudDays;
Fields of TuyaSmartCloudDayModel
Field | Type | Description |
---|---|---|
sumDuration | NSInteger | The total length of the cloud-stored video footage on the current date. |
uploadDay | NSString | The date in the format of yyyy-MM-dd . |
startTime | NSInteger | The Unix timestamp to indicate 00:00:00 on the current date. |
endTime | NSInteger | The Unix timestamp to indicate 23:59:59 on the current date. |
Before cloud-stored video playback, the time model that indicates the duration of each video clip must be queried.
API description
- (void)timeLineWithCloudDay:(TuyaSmartCloudDayModel *)cloudDay
success:(void(^)(NSArray<TuyaSmartCloudTimePieceModel *> * timePieces))success
failure:(void(^)(NSError * error))failure;
Parameters
Parameter | Description |
---|---|
cloudDay | The date model that indicates the duration of each cloud-stored video clip. |
success | The success callback. An array of date models for all video clips on the current date is returned. |
failure | The failure callback. An error message is returned. |
Fields of TuyaSmartCloudTimePieceModel
Field | Type | Description |
---|---|---|
startTime | NSInteger | The start Unix timestamp of a video clip. |
startDate | NSDate | The start date of a video clip. |
endTime | NSInteger | The end Unix timestamp of a video clip. |
endDate | NSDate | The end date of a video clip. |
After the subscription of cloud storage, the smart device detects and reports cloud storage events. These events are linked with cloud-stored video recording. Each cloud storage event results in a cloud-stored video clip in most cases.
Alert events are slightly different from detection messages for cloud storage. They might be triggered in similar ways. However, cloud-stored video footage will not be deleted when detection messages are deleted. Not all detection messages trigger cloud-stored video recording, for example, low battery level.
API description
- (void)timeEventsWithCloudDay:(TuyaSmartCloudDayModel *)cloudDay
offset:(int)offset
limit:(int)limit
success:(void(^)(NSArray<TuyaSmartCloudTimeEventModel *> * timeEvents))success
failure:(void(^)(NSError * error))failure;
Parameters
Parameter | Description |
---|---|
cloudDay | The date model of cloud-stored video footage. |
offset | The event from which video recording is started. A value of 0 indicates the first event. |
limit | The maximum number of events for which video recording is performed. A value of -1 indicates that all events are queried. |
success | The success callback. An array of event models is returned. |
failure | The failure callback. An error message is returned. |
Fields of TuyaSmartCloudTimeEventModel
Field | Type | Description |
---|---|---|
describe | NSString | The description of an event. |
startTime | NSInteger | The start Unix timestamp of an event. |
endTime | NSInteger | The end Unix timestamp of an event. |
snapshotUrl | NSString | The URL of a screenshot captured in real time for an event. |
The screenshots of cloud storage events are encrypted before they can be displayed by the image encryption component TYEncryptImage
. For more information, see Encrypted Images.
Before cloud-stored video playback, the start time, end time, and whether a cloud storage event is linked must be specified. Users can also set the audio switch, local video recording, screenshots, and other options.
TuyaSmartCloudTimePieceModel
):
startTime
to endTime
of TuyaSmartCloudTimePieceModel
.isEvent
to NO
.TuyaSmartCloudTimeEventModel
):
startTime
of TuyaSmartCloudTimeEventModel
.isEvent
to YES
.endTime
of TuyaSmartCloudDayModel
.API description
- (void)playCloudVideoWithStartTime:(long)startTime
endTime:(long)endTime
isEvent:(BOOL)isEvent
onResponse:(void(^)(int errCode))responseCallback
onFinished:(void(^)(int errCode))finishedCallback;
Parameters
Parameter | Description |
---|---|
startTime | The time from which video footage playback is started. |
endTime | The time at which video footage playback is stopped. By default, all video clips on the current date will be automatically played back. |
isEvent | Specifies whether to play back video footage linked with a cloud storage event. |
responseCallback | The callback that is executed when playback is requested. errCode indicates an error message and 0 indicates that playback is started. |
finishedCallback | The callback that is executed when playback is finished. errCode indicates an error message and 0 indicates that playback is finished. |
API description
- (int)pausePlayCloudVideo;
Return values
Type | Description |
---|---|
int | An error message is returned or a value of 0 indicates a successful request. |
API description
- (int)resumePlayCloudVideo;
Return values
Type | Description |
---|---|
int | An error message is returned or a value of 0 indicates a successful request. |
API description
- (int)stopPlayCloudVideo;
Return values
Type | Description |
---|---|
int | An error message is returned or a value of 0 indicates a successful request. |
API description
- (void)downloadCloudVideoWithRange:(NSRange)timeRange
filePath:(NSString *)videoPath
success:(DownloadSuccess)success
progress:(DownloadProgress)progress
failure:(DownloadFailure)failure;
Parameters
Parameter | Description |
---|---|
timeRange | The period in which video clips are downloaded.
|
videoPath | The file path to save video clips. Format: folderPath/fileName.mp4 . |
success | The success callback. |
progress | The callback for the download progress indicated by an integer. Valid values: 0 to 100 . |
failure | The failure callback. |
ObjC
- (void)viewDidLoad {
[_cloudManager downloadCloudVideoWithRange:NSMakeRange(startTime, length) filePath:videoPath success:^(NSString *filePath) {
} progress:^(NSUInteger progress) {
} failure:^(NSError *error) {
}];
}
Swift
func viewDidLoad() {
cloudManager.downloadCloudVideo(with: NSRange(location: startTime, length: length), filePath: videoPath, success: { (filePath) in }, progress: { (progress) in }, failure: { (error) in }
}
API description
- (void)pauseDownloadCloudVideo;
API description
- (void)resumeDownloadCloudVideo:(DownloadFailure)failure;
Parameters
Parameter | Description |
---|---|
failure | The failure callback. |
API description
- (void)cancelDownloadCloudVideo;
API description
- (void)deleteCloudVideoWithRange:(NSRange)timeRange success:(void(^)(void))success failure:(void(^)(NSError *error))failure;
Parameters
Parameter | Description |
---|---|
timeRange | The period in which video clips are deleted.
|
success | The success callback. |
failure | The failure callback. |
ObjC
- (void)viewDidLoad {
[_cloudManager deleteCloudVideoWithRange:NSMakeRange(startTime, length) success:^{
} failure:^(NSError *error) {
}];
}
Swift
func viewDidLoad() {
cloudManager.deleteCloudVideo(with: NSRange(location: startTime, length: length), success: {
}, failure: { error in
})
}
API description
- (void)deleteAllDayCloudVideoWithRange:(NSRange)timeRange success:(void(^)(void))success failure:(void(^)(NSError *error))failure;
Parameters
Parameter | Description |
---|---|
timeRange | The period of the day on which video clips are deleted.
|
success | The success callback. |
failure | The failure callback. |
ObjC
- (void)viewDidLoad {
[_cloudManager deleteAllDayCloudVideoWithRange:NSMakeRange(startTime, length) success:^{
} failure:^(NSError *error) {
}];
}
Swift
func viewDidLoad() {
cloudManager.deleteAllDayCloudVideo(with: NSRange(location: startTime, length: length), success: {
}, failure: { error in
})
}
TuyaSmartCloudManager
is used to implement automatic rendering of cloud-stored video footage. The videoView
method can be called to query cloud-stored video rendering views and add these views to the screen.
API description
- (UIView<TuyaSmartVideoViewType> *)videoView;
Return values
Type | Description |
---|---|
UIView |
The video rendering view. |
API description
- (void)enableMute:(BOOL)mute success:(void(^)(void))success failure:(void (^)(NSError * error))failure;
Parameters
Parameter | Description |
---|---|
mute | Specifies whether to mute the video. |
success | The success callback. |
failure | The failure callback. An error message is returned. |
API description
- (BOOL)isMuted;
Return values
Type | Description |
---|---|
BOOL | Indicates whether the video is muted. |
API description
- (void)startRecord;
API description
- (void)startRecordAtPath:(NSString *)filePath;
Parameters
Parameter | Description |
---|---|
filePath | The path in which the video footage is stored. |
API description
- (void)startRecordWithRotateDirection:(TuyaSmartVideoRotateDirection)direction filePath:(NSString *)filePath;
Parameters
Parameter | Description |
---|---|
direction | The direction to which the camera faces when video is recorded. |
filePath | The path in which the videos are stored. |
API description
- (int)stopRecord;
Return values
Type | Description |
---|---|
int | An error message is returned or a value of 0 indicates that files are saved successfully. |
API description
- (UIImage *)snapShoot;
Return values
Type | Description |
---|---|
UIImage | The UIImage object of a video screenshot. If nil is returned, the system failed to save the screenshot. |
API description
- (UIImage *)snapShootAtPath:(NSString *)filePath thumbnilPath:(NSString *)thumbnilPath;
Parameters
Parameter | Description |
---|---|
filePath | The path in which screenshots are stored. |
thumbnilPath | The path to save the thumbnail. Set the value to nil if this parameter is not required. |
To query the UIImage
object of the current screenshot, the screenshot does not need to be automatically saved. You can call the method - (UIImage *)screenshot;
of videoView
to query the screenshot.
ObjC:
// self.devId = @"xxxxx";
- (void)viewDidLoad {
_cloudManager = [[TuyaSmartCloudManager alloc] initWithDeviceId:self.devId];
[_cloudManager enableMute:NO success:nil failure:nil];
_cloudManager.delegate = self;
}
- (void)loadData {
__weak typeof(self) weakSelf = self;
[self.cloudManager loadCloudData:^(TuyaSmartCloudState state) {
weak_self.cloudStorageDays = weak_self.cloudManager.cloudDays;
weak_self.selectedDay = weak_self.cloudManager.cloudDays.lastObject;
[weakSelf checkCloudState:state];
}];
}
- (void)requestTimelineData {
[self.cloudManager timeLineWithCloudDay:self.selectedDay success:^(NSArray<TuyaSmartCloudTimePieceModel *> *timePieces) {
// success
} failure:^(NSError *error) {
// failed
}];
}
-(void)playVideo:(TuyaSmartCloudTimePieceModel *)timePiece {
[self.cloudManager playCloudVideoWithStartTime:timePiece.startTime endTime:self.selectedDay.endTime isEvent:NO onResponse:^(int errCode) {
if (errCode == 0) {
// success
}else {
// failed
}
} onFinished:^(int errCode) {
// finished
if (errCode != 0) {
// some error
}
}];
}
- (void)playEvent:(TuyaSmartCloudTimeEventModel *)event {
[self.cloudManager playCloudVideoWithStartTime:event.startTime endTime:self.selectedDay.endTime isEvent:YES onResponse:^(int errCode) {
if (errCode == 0) {
// success
}else {
// failed
}
} onFinished:^(int errCode) {
// finished
if (errCode != 0) {
// some error
}
}];
}
- (void)pause {
if ([self.cloudManager pausePlayCloudVideo] != 0) {
// Failed to pause playback.
}
}
- (void)resume {
if ([self.cloudManager resumePlayCloudVideo] != 0) {
// Failed to resume playback.
}
}
- (void)stop {
[self.cloudManager stopPlayCloudVideo];
}
- (void)muteAction {
BOOL isMuted = [self.cloudManger isMuted];
[self.cloudManager enableMute:!isMuted success:^{
// success
} failure:^(NSError *error) {
// failed
}];
}
- (void)recordAction {
if (self.isRecording) {
if ([self.cloudManager stopRecord] != 0) {
// Failed to create video footage.
}else {
// Video footage is created and saved to a system album.
}
self.isRecording = NO;
}else {
[self.cloudManager startRecord];
self.isRecording = YES;
}
}
- (void)snapShoot {
if ([self.cloudManager snapShoot]) {
// A video screenshot is captured and saved to a system album.
}else {
// Failed to capture a screenshot.
}
}
Swift:
func viewDidLoad() {
let cloudManager = TuyaSmartCloudManager(deviceId: devId)
cloudManager?.enableMute(false, success: nil, failure: nil)
cloudManager?.delegate = self
}
func loadData() {
self.cloudManager.loadCloudData { [weak self] (state) in
self.cloudStorageDays = self.cloudManager.cloudDays
self.selectedDay = self.cloudManager.cloudDays.last
self.checkCloudState(state)
}
}
func requestTimelineData() {
self.cloudManager.timeLine(withCloudDay: self.selectedDay, success: { (timePieces) in
//success
}) { (error) in
//failed
}
}
func playVideo(_ timePiece: TuyaSmartCloudTimePieceModel) {
self.cloudManager.playCloudVideo(withStartTime: timePiece.startTime, endTime:self.selectedDay.endTime , isEvent: false, onResponse: { (code) in
if code == 0 {
//success
} else {
//failed
}
}) { (errCode) in
//finished
if codeCode != 0 {
//some error
}
}
}
func playEvent(_ event: TuyaSmartCloudTimeEventModel) {
cloudManager.playCloudVideo(withStartTime: event.startTime, endTime: self.selectedDay.endTime, isEvent: true, onResponse: { (errCode) in
if code == 0 {
//success
} else {
//failed
}
}) { (errCode) in
//finished
if errCode != 0 {
// some error
}
}
}
func pause() {
if self.cloudManager.pausePlayCloudVideo() != 0 {
// Failed to pause playback.
}
}
func resume() {
if self.cloudManager.resumePlayCloudVideo() != 0 {
// Failed to resume playback.
}
}
func stop() {
self.cloudManager.stopPlayCloudVideo()
}
func muteAction() {
let isMuted = self.cloudManager.isMuted()
self.cloudManager.enableMute(!isMuted, success: {
// success
}) { (error) in
// failed
}
}
func recordAction() {
if self.isRecording {
if self.cloudManager.stopRecord() != 0 {
// Failed to create video footage.
} else {
// Video footage is created and saved to a system album.
}
self.isRecording = false
} else {
self.cloudManager.startRecord()
self.isRecording = true
}
}
func snapShoot() {
if self.cloudManager.snapShoot() {
// A video screenshot is captured and saved to a system album.
} else {
// Failed to capture a screenshot.
}
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback