Cloud Storage Recording

Last Updated on : 2024-07-17 08:51:47download

Smart cameras support the cloud storage service that allows users to save video footage on the camera 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 inactive 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 Recording

Core methods

Demo Class Method Description Notes
ThingSmartCloudManager + (BOOL)isSupportCloudStorage: Check support for cloud storage. -
- (instancetype)initWithDeviceId: Create a cloud storage management object. One device ID matches one cloud storage management object.
- (void)loadCloudData: Load cloud storage data. The callback returns the state. If the state is valid, you can query the cloud storage data. See ThingSmartCloudState for state details.
- (void)timeLineWithCloudDay:success:failure: Query cloud-stored clips on the specified date. Return an array of time data models ThingSmartCloudTimePieceModel for all video clips of the day.
- (void)queryAIDetectConfigSuccess:failure: Query AI-based cloud storage settings on device.
  • isAiDevice: Support for AI-based detection.
  • switchState: Whether to enable AI-based detection.
  • aiItemList: The supported AI information.
- (void)enableAIDetect:success:failure: Enable/disable AI-based detection. enable: Specifies whether to enable AI-enabled detection.
- (void)timeEventsWithCloudDay:offset:limit:aiCodes:success:failure: Query cloud storage events.
  • If aiCodes is empty, regular cloud storage events will be queried.
  • If aiCodes has a value, AI-based cloud storage events will be queried.
- (int)playCloudVideoWithStartTime:endTime:isEvent:onResponse:onFinished: Start playing the cloud-stored clip. isEvent: Indicates whether this is a cloud storage event.
- (int)stopPlayCloudVideo Stop playing the cloud-stored clip. -
- (void)destroy Destroy resources. -
ThingSmartCloudManagerDelegate - (void)cloudManager:didReceivedFrame:videoFrameInfo: The delegate callback for cloud-stored video data. The default player has been set. To customize video rendering, you can set autoRender to NO and render the video with a callback. The frameBuffer contains the YUV data of the video frames.

Important notes

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.

Core code

Query cloud storage status

- (void)loadCloudData:(void(^)(ThingSmartCloudState state))complete;

Query video clips within a specified period

- (void)timeLineWithCloudDay:(ThingSmartCloudDayModel *)cloudDay
                     success:(void(^)(NSArray<ThingSmartCloudTimePieceModel *> * timePieces))success
                     failure:(void(^)(NSError * error))failure;

Start playing cloud-stored clips

- (void)playCloudVideoWithStartTime:(long)startTime
                            endTime:(long)endTime
                            isEvent:(BOOL)isEvent
                         onResponse:(void(^)(int errCode))responseCallback
                         onFinished:(void(^)(int errCode))finishedCallback;

Stop playing cloud-stored clips

- (int)stopPlayCloudVideo;

Example

// Initialize cloud storage management class
- (void)cloudstorageManagerInit {
    // Check if cloud storage is supported.
    BOOL isSupportCloudStorage = [ThingSmartCloudManager isSupportCloudStorage:self.devId];

    // Create a cloud storage management class
    _cloudManager = [[ThingSmartCloudManager alloc] initWithDeviceId:self.devId];
    [_cloudManager enableMute:NO success:nil failure:nil];
    _cloudManager.delegate = self;
}

// Check cloud storage activation status
- (void)queryCloudstroageState {
    __weak typeof(self) weakSelf = self;
    [self.cloudManager loadCloudData:^(ThingSmartCloudState state) {
        if (state == ThingSmartCloudStateValidData || state == ThingSmartCloudStateExpiredData) {
            weak_self.cloudStorageDays = weak_self.cloudManager.cloudDays;
            weak_self.selectedDay = weak_self.cloudManager.cloudDays.lastObject;
            if (state == ThingSmartCloudStateExpiredData) {
                // The cloud storage has expired. Prompt the user to subscribe.
            }
        } else {
            // Prompt the user to subscribe to cloud storage.
        }
  }];
}

// Get video clips
- (void)queryTimePieces {
    [self.cloudManager timeLineWithCloudDay:self.selectedDay success:^(NSArray<ThingSmartCloudTimePieceModel *> *timePieces) {
        // Succeeded
    } failure:^(NSError *error) {
        // Failed
    }];
}

// Play video clips
-(void)playVideoWithTimePiece:(ThingSmartCloudTimePieceModel *)timePiece {
    [self.cloudManager playCloudVideoWithStartTime:timePiece.startTime endTime:self.selectedDay.endTime isEvent:NO onResponse:^(int errCode) {
        if (errCode == 0) {
            // Succeeded
        }else {
            // Failed
        }
    } onFinished:^(int errCode) {
        // finished
        if (errCode != 0) {
            // Error
        }
    }];
}

// Play cloud storage event
- (void)playVideoEvent:(ThingSmartCloudTimeEventModel *)event {
    [self.cloudManager playCloudVideoWithStartTime:event.startTime endTime:self.selectedDay.endTime isEvent:YES onResponse:^(int errCode) {
        if (errCode == 0) {
            // Succeeded
        }else {
            // Failed
        }
    } onFinished:^(int errCode) {
        // finished
        if (errCode != 0) {
            // Error
        }
    }];
}

// Stop playing
- (void)stopPlayCloudVideo {
    [self.cloudManager stopPlayCloudVideo];
}

// Destroy
- (void)destroy {
    [self.cloudManage destroy];
}