10a5c7a17Sopenharmony_ci/* 20a5c7a17Sopenharmony_ci * Copyright (c) 2020 Huawei Device Co., Ltd. 30a5c7a17Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 40a5c7a17Sopenharmony_ci * you may not use this file except in compliance with the License. 50a5c7a17Sopenharmony_ci * You may obtain a copy of the License at 60a5c7a17Sopenharmony_ci * 70a5c7a17Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 80a5c7a17Sopenharmony_ci * 90a5c7a17Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 100a5c7a17Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 110a5c7a17Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 120a5c7a17Sopenharmony_ci * See the License for the specific language governing permissions and 130a5c7a17Sopenharmony_ci * limitations under the License. 140a5c7a17Sopenharmony_ci */ 150a5c7a17Sopenharmony_ci 160a5c7a17Sopenharmony_ci#ifndef OHOS_CAMERA_DEVICE_H 170a5c7a17Sopenharmony_ci#define OHOS_CAMERA_DEVICE_H 180a5c7a17Sopenharmony_ci 190a5c7a17Sopenharmony_ci#include <cstdbool> 200a5c7a17Sopenharmony_ci#include <thread> 210a5c7a17Sopenharmony_ci#include <vector> 220a5c7a17Sopenharmony_ci 230a5c7a17Sopenharmony_ci#include "camera_ability.h" 240a5c7a17Sopenharmony_ci#include "camera_config.h" 250a5c7a17Sopenharmony_ci#include "codec_type.h" 260a5c7a17Sopenharmony_ci#include "frame_config.h" 270a5c7a17Sopenharmony_ci#include "surface.h" 280a5c7a17Sopenharmony_ciusing namespace std; 290a5c7a17Sopenharmony_cinamespace OHOS { 300a5c7a17Sopenharmony_cinamespace Media { 310a5c7a17Sopenharmony_cienum LoopState { 320a5c7a17Sopenharmony_ci LOOP_IDLE, 330a5c7a17Sopenharmony_ci LOOP_READY, 340a5c7a17Sopenharmony_ci LOOP_LOOPING, 350a5c7a17Sopenharmony_ci LOOP_STOP, 360a5c7a17Sopenharmony_ci LOOP_ERROR, 370a5c7a17Sopenharmony_ci}; 380a5c7a17Sopenharmony_ciconst int32_t RECORDER_MAX_NUM = 2; 390a5c7a17Sopenharmony_ciclass DeviceAssistant { 400a5c7a17Sopenharmony_cipublic: 410a5c7a17Sopenharmony_ci std::thread *thrd_ = nullptr; 420a5c7a17Sopenharmony_ci LoopState state_ = LOOP_IDLE; 430a5c7a17Sopenharmony_ci FrameConfig *fc_ = nullptr; 440a5c7a17Sopenharmony_ci uint32_t cameraId_; 450a5c7a17Sopenharmony_ci uint32_t streamId_; 460a5c7a17Sopenharmony_ci 470a5c7a17Sopenharmony_ci virtual int32_t SetFrameConfig(FrameConfig &fc, uint32_t *streamId) 480a5c7a17Sopenharmony_ci { 490a5c7a17Sopenharmony_ci return -1; 500a5c7a17Sopenharmony_ci } 510a5c7a17Sopenharmony_ci virtual int32_t Start(uint32_t streamId) 520a5c7a17Sopenharmony_ci { 530a5c7a17Sopenharmony_ci return -1; 540a5c7a17Sopenharmony_ci } 550a5c7a17Sopenharmony_ci virtual int32_t Stop() 560a5c7a17Sopenharmony_ci { 570a5c7a17Sopenharmony_ci return -1; 580a5c7a17Sopenharmony_ci } 590a5c7a17Sopenharmony_ci}; 600a5c7a17Sopenharmony_ci 610a5c7a17Sopenharmony_cistruct CodecDesc { 620a5c7a17Sopenharmony_ci CODEC_HANDLETYPE vencHdl_; 630a5c7a17Sopenharmony_ci list<Surface *> vencSurfaces_; 640a5c7a17Sopenharmony_ci}; 650a5c7a17Sopenharmony_ci 660a5c7a17Sopenharmony_ciclass RecordAssistant : public DeviceAssistant { 670a5c7a17Sopenharmony_cipublic: 680a5c7a17Sopenharmony_ci int32_t SetFrameConfig(FrameConfig &fc, uint32_t *streamId) override; 690a5c7a17Sopenharmony_ci int32_t Start(uint32_t streamId) override; 700a5c7a17Sopenharmony_ci int32_t Stop() override; 710a5c7a17Sopenharmony_ci void ClearFrameConfig(); 720a5c7a17Sopenharmony_ci static int OnVencBufferAvailble(UINTPTR userDate, CodecBuffer *outBuf, int32_t *acquireFd); 730a5c7a17Sopenharmony_ci static CodecCallback recordCodecCb_; 740a5c7a17Sopenharmony_ciprivate: 750a5c7a17Sopenharmony_ci int32_t SetFrameConfigEnd(int32_t result); 760a5c7a17Sopenharmony_ci vector<CodecDesc> codecInfo_; 770a5c7a17Sopenharmony_ci int32_t streamIdNum_[RECORDER_MAX_NUM] = {-1, -1}; 780a5c7a17Sopenharmony_ci}; 790a5c7a17Sopenharmony_ci 800a5c7a17Sopenharmony_ciclass PreviewAssistant : public DeviceAssistant { 810a5c7a17Sopenharmony_cipublic: 820a5c7a17Sopenharmony_ci int32_t SetFrameConfig(FrameConfig &fc, uint32_t *streamId) override; 830a5c7a17Sopenharmony_ci int32_t Start(uint32_t streamId) override; 840a5c7a17Sopenharmony_ci int32_t Stop() override; 850a5c7a17Sopenharmony_ci Surface *capSurface_ = nullptr; 860a5c7a17Sopenharmony_ciprivate: 870a5c7a17Sopenharmony_ci pthread_t threadId; 880a5c7a17Sopenharmony_ci static void *YuvCopyProcess(void *arg); 890a5c7a17Sopenharmony_ci}; 900a5c7a17Sopenharmony_ci 910a5c7a17Sopenharmony_ciclass CaptureAssistant : public DeviceAssistant { 920a5c7a17Sopenharmony_ci int32_t SetFrameConfig(FrameConfig &fc, uint32_t *streamId) override; 930a5c7a17Sopenharmony_ci int32_t Start(uint32_t streamId) override; 940a5c7a17Sopenharmony_ci int32_t Stop() override; 950a5c7a17Sopenharmony_ci CODEC_HANDLETYPE vencHdl_ = nullptr; 960a5c7a17Sopenharmony_ci Surface *capSurface_ = nullptr; 970a5c7a17Sopenharmony_ci}; 980a5c7a17Sopenharmony_ci 990a5c7a17Sopenharmony_ciclass CallbackAssistant : public DeviceAssistant { 1000a5c7a17Sopenharmony_cipublic: 1010a5c7a17Sopenharmony_ci int32_t SetFrameConfig(FrameConfig &fc, uint32_t *streamId) override; 1020a5c7a17Sopenharmony_ci int32_t Start(uint32_t streamId) override; 1030a5c7a17Sopenharmony_ci int32_t Stop() override; 1040a5c7a17Sopenharmony_ci Surface *capSurface_ = nullptr; 1050a5c7a17Sopenharmony_ciprivate: 1060a5c7a17Sopenharmony_ci pthread_t threadId; 1070a5c7a17Sopenharmony_ci static void *StreamCopyProcess(void *arg); 1080a5c7a17Sopenharmony_ci}; 1090a5c7a17Sopenharmony_ci 1100a5c7a17Sopenharmony_ciclass CameraDevice { 1110a5c7a17Sopenharmony_cipublic: 1120a5c7a17Sopenharmony_ci CameraDevice(); 1130a5c7a17Sopenharmony_ci explicit CameraDevice(uint32_t cameraId); 1140a5c7a17Sopenharmony_ci virtual ~CameraDevice(); 1150a5c7a17Sopenharmony_ci 1160a5c7a17Sopenharmony_ci int32_t Initialize(); 1170a5c7a17Sopenharmony_ci int32_t UnInitialize(); 1180a5c7a17Sopenharmony_ci int32_t SetCameraConfig(); 1190a5c7a17Sopenharmony_ci int32_t TriggerLoopingCapture(FrameConfig &fc, uint32_t *streamId); 1200a5c7a17Sopenharmony_ci void StopLoopingCapture(int32_t type); 1210a5c7a17Sopenharmony_ci int32_t TriggerSingleCapture(FrameConfig &fc, uint32_t *streamId); 1220a5c7a17Sopenharmony_ci uint32_t GetCameraId(); 1230a5c7a17Sopenharmony_ciprivate: 1240a5c7a17Sopenharmony_ci uint32_t cameraId; 1250a5c7a17Sopenharmony_ci RecordAssistant recordAssistant_; 1260a5c7a17Sopenharmony_ci PreviewAssistant previewAssistant_; 1270a5c7a17Sopenharmony_ci CaptureAssistant captureAssistant_; 1280a5c7a17Sopenharmony_ci CallbackAssistant callbackAssistant_; 1290a5c7a17Sopenharmony_ci}; 1300a5c7a17Sopenharmony_ci} // namespace Media 1310a5c7a17Sopenharmony_ci} // namespace OHOS 1320a5c7a17Sopenharmony_ci#endif // OHOS_CAMERA_DEVICE_H