• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// @ts-nocheck
2
3import camera from '@ohos.multimedia.camera'
4import deviceInfo from '@ohos.deviceInfo'
5import fileio from '@ohos.fileio'
6import image from '@ohos.multimedia.image'
7import media from '@ohos.multimedia.media'
8import mediaLibrary from '@ohos.multimedia.mediaLibrary'
9import Logger from '../model/Logger'
10import MediaUtils from '../model/MediaUtils'
11import prompt from '@ohos.prompt';
12import fs from '@ohos.file.fs';
13import screen from '@ohos.screen';
14
15const CameraSize = {
16  WIDTH: 1280,
17  HEIGHT: 720
18}
19
20class CameraService {
21  private tag: string = 'qlw CameraService'
22  private static instance: CameraService = new CameraService()
23  private mediaUtil = MediaUtils.getInstance()
24  private cameraManager: camera.CameraManager = undefined
25  cameras: Array<camera.CameraDevice> = undefined
26  private cameraInput: camera.CameraInput = undefined
27  private previewOutput: camera.PreviewOutput = undefined
28  private photoOutput: camera.PhotoOutput = undefined
29  private cameraOutputCapability: camera.CameraOutputCapability = undefined
30  private captureSession: camera.CaptureSession = undefined
31  private mReceiver: image.ImageReceiver = undefined
32  private fileAsset: mediaLibrary.FileAsset = undefined
33  private fd: number = -1
34  private videoRecorder: media.VideoRecorder = undefined
35  private videoOutput: camera.VideoOutput = undefined
36  private handleTakePicture: (photoUri: string) => void = undefined
37  private videoConfig: any = {
38    audioSourceType: 1,
39    videoSourceType: 0,
40    profile: {
41      audioBitrate: 48000,
42      audioChannels: 2,
43      audioCodec: 'audio/mp4v-es',
44      audioSampleRate: 48000,
45      durationTime: 1000,
46      fileFormat: 'mp4',
47      videoBitrate: 280000,
48      videoCodec: 'video/mp4v-es',
49      videoFrameWidth: 640,
50      videoFrameHeight: 480,
51      videoFrameRate: 15,
52
53    },
54    rotation: 270,
55    url: '',
56    orientationHint: 0,
57    location: { latitude: 30, longitude: 130 },
58    maxSize: 10000,
59    maxDuration: 10000
60  }
61  private videoProfileObj: camera.VideoProfile = {
62    format: 1,
63    size: {
64      "width": 640,
65      "height": 480
66    },
67    frameRateRange: {
68      "min": 5,
69      "max": 5
70    }
71  }
72  private photoProfileObj: camera.Profile = {
73    format: 1,
74    size: {
75      "width": 640,
76      "height": 480
77    }
78  }
79  private videoOutputStopBol: boolean = true
80  resolution: any = null
81  photoResolution: any = null
82  videoResolution: any = null
83  screensObj: any = null
84
85  async getScreensObj() {
86    let screens = await screen.getAllScreens()
87    this.screensObj = screens[0].supportedModeInfo
88    Logger.info(this.tag, ` this.screensObj success` + JSON.stringify(this.screensObj))
89  }
90
91  constructor() {
92    try {
93      this.mReceiver = image.createImageReceiver(CameraSize.WIDTH, CameraSize.HEIGHT, image.ImageFormat.JPEG, 8)
94      Logger.info(this.tag, 'createImageReceiver')
95      this.mReceiver.on('imageArrival', () => {
96        Logger.info(this.tag, 'imageArrival')
97        this.mReceiver.readNextImage((err, image) => {
98          Logger.info(this.tag, 'readNextImage')
99          if (err || image === undefined) {
100            Logger.error(this.tag, 'failed to get valid image')
101            return
102          }
103          image.getComponent(4, (errMsg, img) => {
104            Logger.info(this.tag, 'getComponent')
105            if (errMsg || img === undefined) {
106              Logger.info(this.tag, 'failed to get valid buffer')
107              return
108            }
109            let buffer
110            if (img.byteBuffer) {
111              buffer = img.byteBuffer
112            } else {
113              Logger.error(this.tag, 'img.byteBuffer is undefined')
114            }
115            this.savePicture(buffer, image)
116          })
117        })
118      })
119    } catch (err) {
120      Logger.info(this.tag, `image Receiver err ${err.message}`)
121    }
122  }
123
124  async savePicture(buffer: ArrayBuffer, img: image.Image) {
125    try {
126      Logger.info(this.tag, 'savePicture')
127      let imgFileAsset = await this.mediaUtil.createAndGetUri(mediaLibrary.MediaType.IMAGE)
128      let imgPhotoUri = imgFileAsset.uri
129      Logger.info(this.tag, `photoUri = ${imgPhotoUri}`)
130      let imgFd = await this.mediaUtil.getFdPath(imgFileAsset)
131      Logger.info(this.tag, `fd = ${imgFd}`)
132      await fileio.write(imgFd, buffer)
133      await imgFileAsset.close(imgFd)
134      await img.release()
135      Logger.info(this.tag, 'save image done')
136      if (this.handleTakePicture) {
137        this.handleTakePicture(imgPhotoUri)
138      }
139    } catch (err) {
140      Logger.info(this.tag, `save picture err ${err.message}`)
141    }
142  }
143
144  async initCamera(surfaceId: number, cameraDeviceIndex: number, obj?, photoIndex?, previewObj?) {
145    try {
146      if (deviceInfo.deviceType === 'default') {
147        this.videoConfig.videoSourceType = 1
148      } else {
149        this.videoConfig.videoSourceType = 0
150      }
151      Logger.info(this.tag, `cameraDeviceIndex success: ${cameraDeviceIndex}`)
152      await this.getScreensObj()
153      await this.releaseCamera()
154      await this.getCameraManagerFn()
155      await this.getSupportedCamerasFn()
156      await this.getSupportedOutputCapabilityFn(cameraDeviceIndex)
157      if (previewObj) {
158        previewObj.format = this.cameraOutputCapability.previewProfiles[0].format
159        Logger.info(this.tag, `previewObj format: ${previewObj.format}`)
160      }
161      await this.createPreviewOutputFn(previewObj ? previewObj : this.cameraOutputCapability.previewProfiles[0], surfaceId)
162      //            await this.createPhotoOutputFn(this.photoProfileObj)
163      await this.createPhotoOutputFn(obj ? obj : this.cameraOutputCapability.photoProfiles[photoIndex?photoIndex:0])
164      await this.createCameraInputFn(this.cameras[cameraDeviceIndex])
165      await this.cameraInputOpenFn()
166      await this.sessionFlowFn()
167
168    } catch (err) {
169      Logger.info(this.tag, 'initCamera err: ' + JSON.stringify(err.message))
170    }
171  }
172
173  // 曝光模式
174  isExposureModeSupportedFn(ind) {
175    try {
176      let status = this.captureSession.isExposureModeSupported(ind)
177      Logger.info(this.tag, `isExposureModeSupported success: ${status}`)
178      prompt.showToast({
179        message: status ? '支持此模式' : '不支持此模式',
180        duration: 2000,
181        bottom: '60%'
182      })
183      // 设置曝光模式
184      this.captureSession.setExposureMode(ind)
185      Logger.info(this.tag, `setExposureMode success`)
186      // 获取当前曝光模式
187      let exposureMode = this.captureSession.getExposureMode()
188      Logger.info(this.tag, `getExposureMode success: ${exposureMode}`)
189    } catch (err) {
190      Logger.info(this.tag, `isExposureModeSupportedFn fail: ${err} , message: ${err.message}, code: ${err.code}`)
191    }
192  }
193
194  // 曝光区域
195  isMeteringPoint(Point1) {
196    try {
197      // 获取当前曝光模式
198      let exposureMode = this.captureSession.getExposureMode()
199      Logger.info(this.tag, `getExposureMode success: ${exposureMode}`)
200      // 设置曝光区域中心点
201      this.captureSession.setMeteringPoint(Point1)
202      Logger.info(this.tag, `setMeteringPoint success`)
203      // 查询曝光区域中心点
204      let exposurePoint = this.captureSession.getMeteringPoint()
205      Logger.info(this.tag, `getMeteringPoint success: ${exposurePoint}`)
206    } catch (err) {
207      Logger.info(this.tag, `isMeteringPoint fail err: ${err}, message: ${err.message}, code: ${err.code}`)
208    }
209  }
210
211  // 曝光补偿
212  isExposureBiasRange(ind) {
213    try {
214      // 查询曝光补偿范围
215      let biasRangeArray = this.captureSession.getExposureBiasRange()
216      Logger.info(this.tag, `getExposureBiasRange success: ${biasRangeArray}`)
217      // 设置曝光补偿
218      this.captureSession.setExposureBias(ind)
219      Logger.info(this.tag, `setExposureBias success: ${ind}`)
220      // 查询当前曝光值
221      let exposureValue = this.captureSession.getExposureValue()
222      Logger.info(this.tag, `getExposureValue success: ${exposureValue}`)
223    } catch (err) {
224      Logger.info(this.tag, `isExposureBiasRange fail err: ${err}, message: ${err.message}, code: ${err.code}`)
225    }
226  }
227
228  // 对焦模式
229  isFocusMode(ind) {
230    try {
231      // 检测对焦模式是否支持
232      let status = this.captureSession.isFocusModeSupported(ind)
233      Logger.info(this.tag, `isFocusModeSupported success: ${status}`)
234      prompt.showToast({
235        message: status ? '支持此模式' : '不支持此模式',
236        duration: 2000,
237        bottom: '60%'
238      })
239      // 设置对焦模式
240      this.captureSession.setFocusMode(ind)
241      Logger.info(this.tag, `setFocusMode success`)
242      // 获取当前对焦模式
243      let afMode = this.captureSession.getFocusMode()
244      Logger.info(this.tag, `getFocusMode success: ${afMode}`)
245    } catch (err) {
246      Logger.info(this.tag, `isFocusMode fail err: ${err}, message: ${err.message}, code: ${err.code}`)
247    }
248  }
249
250  // 对焦点
251  isFocusPoint(Point) {
252    try {
253      // 设置对焦点
254      this.captureSession.setFocusPoint(Point)
255      Logger.info(this.tag, `setFocusPoint success`)
256      // 获取当前对焦点
257      let point = this.captureSession.getFocusPoint()
258      Logger.info(this.tag, `getFocusPoint success: ${point}`)
259    } catch (err) {
260      Logger.info(this.tag, `isFocusPoint fail err: ${err}, message: ${err.message}, code: ${err.code}`)
261    }
262  }
263
264  // 闪光灯
265  hasFlashFn(ind) {
266    try {
267      // 检测是否有闪光灯
268      let status = this.captureSession.hasFlash()
269      Logger.info(this.tag, `hasFlash success: ${status}`)
270      // 检测闪光灯模式是否支持
271      let status1 = this.captureSession.isFlashModeSupported(ind)
272      Logger.info(this.tag, `isFlashModeSupported success: ${status1}`)
273      prompt.showToast({
274        message: status1 ? '支持此模式' : '不支持此模式',
275        duration: 2000,
276        bottom: '60%'
277      })
278      // 设置闪光灯模式
279      this.captureSession.setFlashMode(ind)
280      Logger.info(this.tag, `setFlashMode success`)
281      // 获取当前设备的闪光灯模式
282      let flashMode = this.captureSession.getFlashMode()
283      Logger.info(this.tag, `getFlashMode success: ${flashMode}`)
284    } catch (err) {
285      Logger.info(this.tag, `hasFlashFn fail err: ${err}, message: ${err.message}, code: ${err.code}`)
286    }
287  }
288
289  // 变焦
290  setZoomRatioFn(num) {
291    try {
292      // 获取当前支持的变焦范围
293      let zoomRatioRange = this.captureSession.getZoomRatioRange()
294      Logger.info(this.tag, `getZoomRatioRange success: ${zoomRatioRange}`)
295      // 设置变焦比
296      Logger.info(this.tag, `setZoomRatioFn num: ${num}`)
297      this.captureSession.setZoomRatio(num)
298      Logger.info(this.tag, `setZoomRatio success`)
299      // 获取当前对焦比
300      let zoomRatio = this.captureSession.getZoomRatio()
301      Logger.info(this.tag, `getZoomRatio success: ${zoomRatio}`)
302    } catch (err) {
303      Logger.info(this.tag, `setZoomRatioFn fail err: ${err}, message: ${err.message}, code: ${err.code}`)
304    }
305  }
306
307  // 防抖
308  isVideoStabilizationModeSupportedFn(ind) {
309    try {
310      // 查询是否支持指定的视频防抖模式
311      let isSupported = this.captureSession.isVideoStabilizationModeSupported(ind)
312      Logger.info(this.tag, `isVideoStabilizationModeSupported success: ${isSupported}`)
313      prompt.showToast({
314        message: isSupported ? '支持此模式' : '不支持此模式',
315        duration: 2000,
316        bottom: '60%'
317      })
318      // 设置视频防抖
319      this.captureSession.setVideoStabilizationMode(ind)
320      Logger.info(this.tag, `setVideoStabilizationMode success`)
321      // 查询当前正在使用的防抖模式
322      let vsMode = this.captureSession.getActiveVideoStabilizationMode()
323      Logger.info(this.tag, `getActiveVideoStabilizationMode success: ${vsMode}`)
324    } catch (err) {
325      Logger.info(this.tag, `isVideoStabilizationModeSupportedFn fail err: ${err}, message: ${err.message}, code: ${err.code}`)
326    }
327  }
328
329  setTakePictureCallback(callback) {
330    this.handleTakePicture = callback
331  }
332
333  // 照片方向判断
334  onChangeRotation() {
335    if (globalThis.photoOrientation == 0) {
336      return 0
337    }
338    if (globalThis.photoOrientation == 1) {
339      return 90
340    }
341    if (globalThis.photoOrientation == 2) {
342      return 180
343    }
344    if (globalThis.photoOrientation == 3) {
345      return 270
346    }
347  }
348
349  // 照片地理位置逻辑,后续靠定位实现,当前传入固定值
350  onChangeLocation() {
351    if (globalThis.settingDataObj.locationBol) {
352      return {
353        latitude: 12,
354        longitude: 77,
355        altitude: 1000
356      }
357    }
358    return {
359      latitude: 0,
360      longitude: 0,
361      altitude: 0
362    }
363  }
364
365  // 拍照
366  async takePicture(imageRotation?) {
367    try {
368      Logger.info(this.tag, 'takePicture start')
369      let photoSettings = {
370        rotation: imageRotation ? Number(imageRotation) : 0,
371        quality: 1,
372        location: {
373          latitude: 0,
374          longitude: 0,
375          altitude: 0
376        },
377        mirror: false
378      }
379      Logger.info(this.tag, `photoOutput capture photoSettings: ` + JSON.stringify(photoSettings))
380      await this.photoOutput.capture(photoSettings)
381      Logger.info(this.tag, 'takePicture end')
382    } catch (err) {
383      Logger.info(this.tag, `takePicture fail err: ${err}, message: ${err.message}, code: ${err.code}`)
384    }
385  }
386
387  // 获取Fd
388  async getFileFd() {
389    let filesDir = globalThis.abilityContext.filesDir
390    Logger.info(this.tag, `beginConfig 3`)
391    let path = filesDir + '/' + 'test.mp4'
392    Logger.info(this.tag, `beginConfig 4`)
393    let file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE | fs.OpenMode.TRUNC)
394    Logger.info(this.tag, `getFileFd : ${file.fd}`)
395    return file.fd
396  }
397
398  // 开始录制
399  async startVideo() {
400    try {
401      Logger.info(this.tag, `startVideo begin`)
402      await this.captureSession.stop()
403      await this.captureSession.beginConfig()
404      // await this.captureSession.removeOutput(this.photoOutput);
405      this.fd = await this.getFileFd()
406      this.videoRecorder = await media.createVideoRecorder()
407      this.videoConfig.url = `fd://${this.fd}`
408      this.videoConfig.profile.videoFrameWidth = this.cameraOutputCapability.videoProfiles[0].size.width
409      this.videoConfig.profile.videoFrameHeight = this.cameraOutputCapability.videoProfiles[0].size.height
410      await this.videoRecorder.prepare(this.videoConfig)
411      let videoId = await this.videoRecorder.getInputSurface()
412      // Logger.info(this.tag, `videoProfileObj: ` + JSON.stringify(this.videoProfileObj))
413      Logger.info(this.tag, `videoConfig.profile: ` + JSON.stringify(this.videoConfig.profile))
414      Logger.info(this.tag, `videoProfileObj1: ` + JSON.stringify(this.cameraOutputCapability.videoProfiles[0]))
415      this.videoOutput = await this.cameraManager.createVideoOutput(this.cameraOutputCapability.videoProfiles[0], videoId)
416      Logger.info(this.tag, `createVideoOutput success: ${this.videoOutput}`)
417      await this.captureSession.addOutput(this.videoOutput)
418      Logger.info(this.tag, `startVideo begin1`)
419      await this.captureSession.commitConfig()
420      Logger.info(this.tag, `startVideo begin2`)
421      await this.captureSession.start()
422      Logger.info(this.tag, `startVideo begin3`)
423      await this.videoOutput.start()
424      Logger.info(this.tag, `startVideo begin4`)
425      await this.videoRecorder.start().then(() => {
426        setTimeout(async () => {
427          await this.stopVideo()
428          Logger.info(this.tag, `setTimeout stopVideo end`)
429        }, 3000)
430      })
431      Logger.info(this.tag, `videoOutput end`)
432    } catch (err) {
433      Logger.info(this.tag, `startVideo fail err: ${err}, message: ${err.message}, code: ${err.code}`)
434    }
435  }
436
437  // 停止录制
438  async stopVideo() {
439    try {
440      if (this.videoRecorder) {
441        await this.videoRecorder.stop()
442        await this.videoRecorder.release()
443      }
444      if (this.videoOutput) {
445        if (this.videoOutputStopBol) {
446          await this.videoOutput.stop()
447        }
448        await this.videoOutput.release()
449      }
450      if (this.fileAsset) {
451        await this.fileAsset.close(this.fd)
452        return this.fileAsset
453      }
454      Logger.info(this.tag, `stopVideo success`)
455    } catch (err) {
456      Logger.info(this.tag, `stopVideo fail err: ${err}, message: ${err.message}, code: ${err.code}`)
457    }
458  }
459
460  // 查询相机设备在模式下支持的输出能力
461  async getSupportedOutputCapabilityFn(cameraDeviceIndex) {
462    Logger.info(this.tag, `cameraOutputCapability cameraId: ${this.cameras[cameraDeviceIndex].cameraId}`)
463    // @ts-ignore
464    this.cameraOutputCapability = this.cameraManager.getSupportedOutputCapability(this.cameras[cameraDeviceIndex])
465    let previewSize = []
466    let photoSize = []
467    let videoSize = []
468    this.cameraOutputCapability.previewProfiles.forEach((item, index) => {
469      Logger.info(this.tag, `cameraOutputCapability previewProfiles index: ${index}, item:` + JSON.stringify(item))
470      previewSize.push({
471        value: `${item.size.width}x${item.size.height}`
472      })
473    })
474    this.cameraOutputCapability.photoProfiles.forEach((item, index) => {
475      Logger.info(this.tag, `cameraOutputCapability photoProfiles index: ${index}, item:` + JSON.stringify(item))
476      photoSize.push({
477        value: `${item.size.width}x${item.size.height}`
478      })
479    })
480    this.cameraOutputCapability.videoProfiles.forEach((item, index) => {
481      Logger.info(this.tag, `cameraOutputCapability videoProfiles index: ${index}, item:` + JSON.stringify(item))
482      videoSize.push({
483        value: `${item.size.width}x${item.size.height}`
484      })
485    })
486    Logger.info(this.tag, `cameraOutputCapability previewProfiles:` + JSON.stringify(this.cameraOutputCapability.previewProfiles))
487    Logger.info(this.tag, `cameraOutputCapability photoProfiles:` + JSON.stringify(this.cameraOutputCapability.photoProfiles))
488    Logger.info(this.tag, `cameraOutputCapability videoProfiles:` + JSON.stringify(this.cameraOutputCapability.videoProfiles))
489    Logger.info(this.tag, `cameraOutputCapability previewProfiles previewSize:` + JSON.stringify(previewSize))
490    this.resolution = previewSize
491    this.photoResolution = photoSize
492    this.videoResolution = videoSize
493    return previewSize
494  }
495
496  // 释放会话及其相关参数
497  async releaseCamera() {
498    try {
499      if (this.cameraInput) {
500        await this.cameraInput.release()
501      }
502      if (this.previewOutput) {
503        await this.previewOutput.release()
504      }
505      if (this.photoOutput) {
506        await this.photoOutput.release()
507      }
508      if (this.videoOutput) {
509        await this.videoOutput.release()
510      }
511      if (this.captureSession) {
512        await this.captureSession.release()
513      }
514      Logger.info(this.tag, `releaseCamera success`)
515    } catch (err) {
516      Logger.info(this.tag, `releaseCamera fail err: ${err}, message: ${err.message}, code: ${err.code}`)
517    }
518  }
519
520  // 释放会话
521  async releaseSession() {
522    await this.previewOutput.stop()
523    await this.photoOutput.release()
524    await this.captureSession.release()
525    Logger.info(this.tag, `releaseSession success`)
526  }
527
528  // 获取相机管理器实例
529  async getCameraManagerFn() {
530    try {
531      this.cameraManager = await camera.getCameraManager(globalThis.abilityContext)
532      Logger.info(this.tag, `getCameraManager success: ` + JSON.stringify(this.cameraManager))
533    } catch (err) {
534      Logger.info(this.tag, `getCameraManagerFn fail err: ${err}, message: ${err.message}, code: ${err.code}`)
535    }
536  }
537
538  // 获取支持指定的相机设备对象
539  async getSupportedCamerasFn() {
540    try {
541      this.cameras = await this.cameraManager.getSupportedCameras()
542      Logger.info(this.tag, `getSupportedCameras success: ` + JSON.stringify(this.cameras))
543      Logger.info(this.tag, `getSupportedCameras length success: ${this.cameras.length}`)
544    } catch (err) {
545      Logger.info(this.tag, `getSupportedCamerasFn fail err: ${err}, message: ${err.message}, code: ${err.code}`)
546    }
547  }
548
549  // 创建previewOutput输出对象
550  async createPreviewOutputFn(previewProfilesObj, surfaceId) {
551    try {
552      Logger.info(this.tag, `createPreviewOutputFn previewProfilesObj success: ` + JSON.stringify(previewProfilesObj))
553      this.previewOutput = await this.cameraManager.createPreviewOutput(previewProfilesObj, surfaceId.toString())
554      Logger.info(this.tag, `createPreviewOutputFn success: ` + JSON.stringify(this.previewOutput))
555    } catch (err) {
556      Logger.info(this.tag, `createPreviewOutputFn fail err: ${err}, message: ${err.message}, code: ${err.code}`)
557    }
558  }
559
560  // 创建photoOutput输出对象
561  async createPhotoOutputFn(photoProfileObj) {
562    try {
563      Logger.info(this.tag, `createPhotoOutputFn photoProfileObj success: ` + JSON.stringify(photoProfileObj))
564      let mSurfaceId = await this.mReceiver.getReceivingSurfaceId()
565      this.photoOutput = await this.cameraManager.createPhotoOutput(photoProfileObj, mSurfaceId)
566      Logger.info(this.tag, `createPhotoOutputFn success: ` + JSON.stringify(this.photoOutput))
567    } catch (err) {
568      Logger.info(this.tag, `createPhotoOutputFn fail err: ${err}, message: ${err.message}, code: ${err.code}`)
569    }
570  }
571
572  // 创建cameraInput输出对象
573  async createCameraInputFn(cameraDeviceIndex) {
574    try {
575      this.cameraInput = await this.cameraManager.createCameraInput(cameraDeviceIndex)
576      Logger.info(this.tag, `createCameraInputFn success: ${this.cameraInput}`)
577    } catch (err) {
578      Logger.info(this.tag, `createCameraInputFn fail err: ${err}, message: ${err.message}, code: ${err.code}`)
579    }
580  }
581
582  // 打开相机
583  async cameraInputOpenFn() {
584    await this.cameraInput.open()
585      .then((data) => {
586        Logger.info(this.tag, `cameraInputOpenFn open success: ${data}`)
587      })
588      .catch((err) => {
589        Logger.info(this.tag, `cameraInputOpenFn fail err: ${err}, message: ${err.message}, code: ${err.code}`)
590      })
591  }
592
593  // 会话流程
594  async sessionFlowFn() {
595    try {
596      // 创建captureSession实例
597      this.captureSession = await this.cameraManager.createCaptureSession()
598      // 开始配置会话
599      await this.captureSession.beginConfig()
600      // cameraInput加入会话
601      await this.captureSession.addInput(this.cameraInput)
602      // previewOutput加入会话
603      await this.captureSession.addOutput(this.previewOutput)
604      // photoOutput加入会话
605      await this.captureSession.addOutput(this.photoOutput)
606      // 提交配置会话
607      await this.captureSession.commitConfig()
608      // 开启会话
609      await this.captureSession.start()
610      Logger.info(this.tag, `sessionFlowFn success`)
611    } catch (err) {
612      Logger.info(this.tag, `sessionFlowFn fail err: ${err}, message: ${err.message}, code: ${err.code}`)
613    }
614  }
615}
616
617export default new CameraService()