Multi-Lens IPC

Last Updated on : 2024-06-17 07:54:00download

The IPC SDK allows for displaying video from multiple cameras on a single screen by using a video splitting protocol for rendering, which relies on device support.

  • Make sure to obtain the device data model successfully.
  • First, initialize the ThingSmartCameraType object and then invoke the video splitting APIs.
  • When you develop with the SDK, it is recommended to enable the debug mode.

Check video splitting support

API description

Check if the device supports video splitting and return a Boolean value.

@property (nonatomic, assign, readonly) BOOL isSupportedVideoSplitting;

Example

id<ThingSmartCameraType> camera = [ThingSmartCameraFactory cameraWithP2PType:p2pType config:config delegate:self];
if (camera.advancedConfig) {
    return camera.advancedConfig.isSupportedVideoSplitting;
}
return NO;

Get video splitting protocol

API description

Get the video splitting protocol in JSON.

@property (nonatomic, copy, readonly) NSString *cameraSplitVideoInfoJson;

Example

id<ThingSmartCameraType> camera = [ThingSmartCameraFactory cameraWithP2PType:p2pType config:config delegate:self];
if (camera.advancedConfig) {
    return camera.advancedConfig.cameraSplitVideoInfoJson;
}
return nil;

References:

Bind render view with camera ID

API description

Each render view can be bound with one camera ID. This method allows for bulk binding.

Invoke the binding method after you create the camera object.

You can parse the index from the video splitting protocol and assign it to the videoIndex in ThingSmartVideoViewIndexPair.

- (BOOL)registerVideoViewIndexPairs:(NSArray<id<ThingSmartVideoViewIndexPair>> *)viewIndexPairs;

Request parameters

Parameter Subparameter Description
viewIndexPairs videoIndex The camera ID, corresponding to the split_info.index in the video splitting protocol, such as 1, 2, 3.
videoView The view object of the render video stream.

Unbind render view from camera ID

API description

Unbind the render view from one or more camera IDs.

Invoke the unbinding method after you create the camera object.

You can parse the index from the video splitting protocol and assign it to the videoIndex in ThingSmartVideoViewIndexPair.

- (BOOL)uninstallVideoViewIndexPairs:(NSArray<id<ThingSmartVideoViewIndexPair>> *)viewIndexPairs;

Request parameters

Parameter Subparameter Description
viewIndexPairs videoIndex The camera ID, corresponding to the split_info.index in the video splitting protocol, such as 1, 2, 3.
videoView The view object of the render video stream.

Swap camera views

Swap between the video streams rendered by two players.

Before swapVideoIndex:forVideoIndex:, make sure you have invoked registerVideoViewIndexPairs:.

- (BOOL)swapVideoIndex:(ThingSmartVideoIndex)videoIndex forVideoIndex:(ThingSmartVideoIndex)forVideoIndex;

Request parameters

Parameter Description
videoIndex The first camera ID, which should have been bound using registerVideoViewIndexPairs.
forVideoIndex The second camera ID, which should have been bound using registerVideoViewIndexPairs.

Example

[camera swapVideoIndex:1 forVideoIndex:2];

Complete example code

/// Binding information class
@interface CameraDivisionRegisterConfig : NSObject<ThingSmartVideoViewIndexPair>

@end

@implementation CameraDivisionRegisterConfig

@synthesize videoIndex;
@synthesize videoView;

@end
// Create camera
- (void)createCamera {
    if (self.camera) {
        return;
    }

   id p2pType = [self.deviceModel.skills objectForKey:@"p2pType"];
   dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    self.camera = [ThingSmartCameraFactory cameraWithP2PType:p2pType deviceId:devId delegate:self];
  //Bind view
    [self bindRenderView];
    [self.camera connect];
});
}

- (void)bindRenderView {
   //one split video player config
    self.oneSplitVideoPlayerConfig = [[CameraDivisionRegisterConfig alloc] init];
    ThingSmartEAGLView *oneSplitVideoPlayer = [[ThingSmartEAGLView alloc] init];
    self.oneSplitVideoPlayerConfig.videoView = oneSplitVideoPlayer;
    self.oneSplitVideoPlayerConfig.videoIndex = 1;
    
    //two split video player config
    self.twoSplitVideoPlayerConfig = [[CameraDivisionRegisterConfig alloc] init];
    ThingSmartEAGLView *twoSplitVideoPlayer = [[ThingSmartEAGLView alloc] init];
    self.twoSplitVideoPlayerConfig.videoView = twoSplitVideoPlayer;
    self.twoSplitVideoPlayerConfig.videoIndex = 2;

  // Get the camera splitting protocol.
  NSString *splitVideoInfoJson = self.camera.advancedConfig.cameraSplitVideoInfoJson;

  // Register the render view.
   [self.camera registerVideoViewIndexPairs:@[self.oneSplitVideoPlayerConfig,self.twoSplitVideoPlayerConfig]];


  // Add view and layout.
    oneSplitVideoPlayer.frame = CGRectMake(0, 90, ScreenWidth(), ScreenWidth()*9/16);
    twoSplitVideoPlayer.frame = CGRectMake(0, CGRectGetMaxY(oneSplitVideoPlayer.frame),  ScreenWidth(), ScreenWidth()*9/16);

  [self.view addSubview:oneSplitVideoPlayer];
  [self.view addSubview:twoSplitVideoPlayer];

}

// Unbind view
- (void)unRegister {
    [self.camera uninstallVideoViewIndexPairs:@[self.boolConfig,self.blotConfig]];
}

#pragma mark - ThingSmartCameraDelegate
- (void)cameraDidConnected:(id<ThingSmartCameraType>)camera {
    self.connected = YES;
    // Preview can only start after a successful P2P connection.
       [camera startPreview];
}

For more information, see Demo.

Description

Video splitting parameters

Parameter Description
total_split_num The number of channels to split.
split_info An array of information about video splitting.
split_info.index The camera ID.
split_info.type The type of the video stream.
  • -1: Single channel stream.
  • 0: All channels.
  • 1: PTZ camera.
  • 2: Bullet camera.
split_info.res_pos The coordinates.
align_info (Optional) Video window alignment and localizer position.
align_info.align_type Video window alignment. Valid values:
  • 20: Arrange two windows up and down for dual-lens IPCs.
  • 21: Arrange two windows side by side for dual-lens IPCs.
  • 30: Arrange three windows up and down for three-lens IPCs. This value is currently not supported because such devices do not exist.
  • 31: Arrange one window at the top and two windows side by side below for three-lens IPCs.
  • 32: Arrange two windows side by side at the top and one window below for three-lens IPCs.
align_info.align_group The order of cameras. Use the camera ID from split_info.index to specify the order. A non-array element indicates one camera in a row, while nested arrays indicate multiple cameras arranged side by side in a row.
align_info.localizer_group The position with specific localizers split_info.index. Cross-column arrangement is not supported.

Example protocol

{
  "total_split_num":3,
  "split_info":[
    {
      "index":1,
      "type":1,
      "res_pos":[[0,0,640,720],[0,0,960,1080]]
    },
    {
      "index":2,
      "type":2,
      "res_pos":[[0,720,640,720],[0,1080,960,1080]]
    },
    {
      "index":3,
      "type":2,
      "res_pos":[[0,720,1280,720],[0,1080,1920,1080]]
    }
  ],
  "align_info":{
    "align_type":32,
    "align_group":[[1, 3],[2]],
    "localizer_group":[1,3]
  }
}