getScreenCaptureSources method

TRTCScreenCaptureSourceList getScreenCaptureSources(
  1. TRTCSize thumbnail,
  2. TRTCSize icon
)

Implementation

TRTCScreenCaptureSourceList getScreenCaptureSources(TRTCSize thumbnail, TRTCSize icon) {
  TRTCScreenCaptureSourceList list = TRTCScreenCaptureSourceList();

  ffi.Pointer<trtc_size_t> thumbnailPointer = trtc_size_t.fromParams(thumbnail);
  ffi.Pointer<trtc_size_t> iconPointer = trtc_size_t.fromParams(icon);
  ffi.Pointer<trtc_screen_capture_source_list> sourceListPtr = calloc<trtc_screen_capture_source_list>();
  ffi.Pointer<ffi.Int> count = calloc<ffi.Int>();

  _trtcFFIBindings.get_screen_capture_source_list(_trtcsharedInstanceNativePointer, thumbnailPointer.ref, iconPointer.ref, sourceListPtr, count);

  list.count = count.value;

  for (int index = 0; index < list.count; index++) {
    TRTCScreenCaptureSourceInfo info = TRTCScreenCaptureSourceInfo();
    ffi.Pointer<trtc_screen_capture_source_info_t> sourceInfo
      = trtc_screen_capture_source_info_t.create(
          thumbnail.height * thumbnail.width * 4,
          icon.height * icon.width * 4);

    _trtcFFIBindings.get_screen_capture_sources_info(sourceListPtr.value, index, sourceInfo);

    if (sourceInfo != ffi.nullptr) {
      info.type = TRTCScreenCaptureSourceTypeExt.fromValue(sourceInfo.ref.type);
      info.viewId = sourceInfo.ref.source_id.address;
      info.sourceName = FFIConverter.getStringFromChar(sourceInfo.ref.source_name);
      info.thumbBGRA = getImageBuffer(sourceInfo.ref.thumb_bgra);
      info.iconBGRA = getImageBuffer(sourceInfo.ref.icon_bgra);
      info.isMinimizeWindow = (sourceInfo.ref.is_minimize_window == 0);
      info.isMainScreen = (sourceInfo.ref.is_main_screen == 0);
      info.x = sourceInfo.ref.x;
      info.y = sourceInfo.ref.y;
      info.width = sourceInfo.ref.width;
      info.height = sourceInfo.ref.height;

      list.sourceList.add(info);
    }
  }

  trtc_size_t.freeStruct(thumbnailPointer);
  trtc_size_t.freeStruct(iconPointer);

  return list;
}