1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 17export async function initCaptureSession(videoOutPut, cameraManager, cameraDevice, previewOutput) { 18 let cameraInput = await cameraManager.createCameraInput(cameraDevice); 19 if (cameraInput != null) { 20 console.info('[camera] case createCameraInput success'); 21 } else { 22 console.info('[camera] case createCameraInput failed'); 23 return; 24 } 25 await cameraInput.open((err) => { 26 if(err){ 27 console.info('[camera] cameraInput open Failed'); 28 return 29 } 30 console.info('[camera] cameraInput open success'); 31 }) 32 let captureSession = await cameraManager.createCaptureSession(); 33 await captureSession.beginConfig(); 34 await captureSession.addInput(cameraInput); 35 await captureSession.addOutput(previewOutput); 36 await captureSession.addOutput(videoOutPut); 37 await captureSession.commitConfig(); 38 await captureSession.start(); 39 return captureSession; 40} 41 42export async function stopCaptureSession(captureSession) { 43 await captureSession.stop().then(() => { 44 console.info('[camera] case captureSession stop success'); 45 }); 46 await captureSession.release().then(() => { 47 console.info('[camera] case captureSession release success'); 48 }); 49}