1 /* 2 * Copyright (c) 2021 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 #ifndef CAMERA_MANAGER_H 17 #define CAMERA_MANAGER_H 18 19 #include "camera_kit.h" 20 #include "recorder.h" 21 22 #include <algorithm> 23 #include <condition_variable> 24 #include <cstring> 25 #include <fcntl.h> 26 #include <fstream> 27 #include <iostream> 28 #include <mutex> 29 #include <pthread.h> 30 #include <sstream> 31 #include <string> 32 #include <sys/io.h> 33 #include <sys/prctl.h> 34 #include <sys/select.h> 35 #include <sys/stat.h> 36 #include <sys/time.h> 37 #include <sys/types.h> 38 #include <thread> 39 #include <unistd.h> 40 41 namespace IC { 42 // Settings of camera 43 const int32_t CAMERA_PIC_WIDTH = 1920; 44 const int32_t CAMERA_PIC_HEIGHT = 1080; 45 const std::string CAMERA_SAVE_PATH = "/storage/Capture.jpg"; 46 47 // condition_variable for camera 48 extern std::mutex g_mutex; 49 extern std::condition_variable g_cv; 50 51 class SampleFrameStateCallback : public OHOS::Media::FrameStateCallback { 52 public: 53 void OnFrameFinished(OHOS::Media::Camera &camera, 54 OHOS::Media::FrameConfig &fc, 55 OHOS::Media::FrameResult &result) override; 56 }; 57 58 class SampleSurfaceListener : public OHOS::IBufferConsumerListener { 59 public: 60 void SetSurface(OHOS::Media::Surface *surface); 61 void OnBufferAvailable() override; 62 63 private: 64 OHOS::Media::Surface *surface_ = nullptr; 65 }; 66 67 class SampleCameraDeivceCallback : public OHOS::Media::CameraDeviceCallback { 68 }; 69 70 class SampleCameraStateMng : public OHOS::Media::CameraStateCallback { 71 public: 72 SampleCameraStateMng() = delete; 73 explicit SampleCameraStateMng(OHOS::Media::EventHandler &eventHdlr); 74 ~SampleCameraStateMng(); 75 void OnCreated(OHOS::Media::Camera &c) override; 76 void OnCreateFailed(const std::string cameraId, int32_t errorCode) override; 77 void OnReleased(OHOS::Media::Camera &c) override; 78 void Capture(); 79 private: 80 OHOS::Media::EventHandler &eventHdlr_; 81 OHOS::Media::Camera *cam_ = nullptr; 82 SampleSurfaceListener listener_; 83 SampleFrameStateCallback fsCb_; 84 }; 85 } // namespace IC 86 #endif