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 TEST_DISPLAY_H 17 #define TEST_DISPLAY_H 18 #include <gtest/gtest.h> 19 #include "camera.h" 20 #include "camera_host.h" 21 #include "stream_operator.h" 22 #include "camera_device.h" 23 #include "utils.h" 24 #include <thread> 25 #include <map> 26 #include <stdio.h> 27 #include <climits> 28 #include "types.h" 29 #include "camera_device_impl.h" 30 #include "stream_operator_impl.h" 31 #include "idevice_manager.h" 32 #include "camera_metadata_info.h" 33 #include <display_type.h> 34 #include <fcntl.h> 35 #include <unistd.h> 36 #include <sys/ioctl.h> 37 #include <sys/wait.h> 38 #include "buffer_queue_producer.h" 39 #include "buffer_manager.h" 40 #include "test_stream_operator_impl.h" 41 #include "ibuffer.h" 42 #include <algorithm> 43 #include <assert.h> 44 #include <errno.h> 45 #include <getopt.h> 46 #include <linux/fb.h> 47 #include <linux/videodev2.h> 48 #include <mutex> 49 #include <pthread.h> 50 #include <stdlib.h> 51 #include <string.h> 52 #include <sys/mman.h> 53 #include <sys/stat.h> 54 #include <sys/time.h> 55 #include <vector> 56 #include <iostream> 57 #include <cstring> 58 #include <cerrno> 59 #include <securec.h> 60 #include <surface_buffer.h> 61 #include <ibuffer_producer.h> 62 #include <fstream> 63 #define PATH_MAX 128 64 #define BUFFERSCOUNT 8 65 #define CAMERA_BUFFER_QUEUE_IPC 654320 66 #define RANGE_LIMIT(x) (x > 255 ? 255 : (x < 0 ? 0 : x)) 67 68 class TestDisplay { 69 public: 70 // 这个应该根据底层获取size大小设置 71 unsigned int bufSize_ = 614400; // 614400:bufSize 72 unsigned char* displayBuf_; 73 unsigned int camframeV4l2Exit_ = 1; 74 unsigned int numOfReadyFrames_ = 0; 75 unsigned int bufCont_ = BUFFERSCOUNT; 76 pthread_cond_t sub_thread_ready_cond = PTHREAD_COND_INITIALIZER; 77 pthread_mutex_t sub_thread_ready_mutex = PTHREAD_MUTEX_INITIALIZER; 78 pthread_t previewThreadId_; 79 std::mutex readyFrameLock_; 80 81 int fbFd_, readIndex_; 82 struct fb_var_screeninfo vinfo_; 83 struct fb_fix_screeninfo finfo_; 84 85 std::shared_ptr<OHOS::Camera::IStreamOperator> streamOperator = nullptr; 86 std::shared_ptr<OHOS::Camera::IStreamOperatorCallback> streamOperatorCallback = nullptr; 87 std::shared_ptr<OHOS::Camera::CaptureInfo> captureInfo = nullptr; 88 std::vector<std::shared_ptr<OHOS::Camera::StreamInfo>> streamInfos; 89 std::shared_ptr<OHOS::Camera::StreamInfo> streamInfo = nullptr; 90 std::shared_ptr<OHOS::Camera::StreamInfo> streamInfoPre = nullptr; 91 std::shared_ptr<OHOS::Camera::StreamInfo> streamInfoVideo = nullptr; 92 std::shared_ptr<OHOS::Camera::StreamInfo> streamInfoCapture = nullptr; 93 std::shared_ptr<IBufferProducer> producer = nullptr; 94 std::shared_ptr<IBufferProducer> producerCapture = nullptr; 95 std::shared_ptr<IBufferProducer> producerVideo = nullptr; 96 std::shared_ptr<OHOS::Camera::CameraHost> cameraHost = nullptr; 97 std::shared_ptr<OHOS::Camera::ICameraDevice> cameraDevice = nullptr; 98 std::shared_ptr<CameraAbility> ability = nullptr; 99 std::vector<int> captureIds; 100 std::vector<std::string> cameraIds; 101 std::vector<int> streamIds; 102 std::vector<OHOS::Camera::StreamIntent> intents; 103 enum { 104 streamId_preview = 1000, // 1000:preview streamID 105 streamId_capture, 106 streamId_video, 107 captureId_preview = 2000, // 2000:preview captureId 108 captureId_capture, 109 captureId_video 110 }; 111 enum { 112 preview_mode = 0, 113 capture_mode, 114 video_mode 115 }; 116 OHOS::Camera::CamRetCode rc; 117 int init_flag = 0; 118 bool status; 119 120 public: 121 TestDisplay(); 122 uint64_t GetCurrentLocalTimeStamp(); 123 int32_t SaveYUV(char* type, unsigned char* buffer, int32_t size); 124 int DoFbMunmap(unsigned char* addr); 125 unsigned char* DoFbMmap(int* pmemfd); 126 void FBLog(); 127 RetCode FBInit(); 128 void ProcessImage(const unsigned char* p, unsigned char* fbp); 129 void LcdDrawScreen(unsigned char* displayBuf_, unsigned char* addr); 130 void BufferCallback(std::shared_ptr<SurfaceBuffer> buffer, int choice); 131 void Init(); 132 void UsbInit(); 133 void Close(); 134 void OpenCamera(); 135 void AchieveStreamOperator(); 136 void StartStream(std::vector<OHOS::Camera::StreamIntent> intents); 137 void StopStream(std::vector<int>& captureIds, std::vector<int>& streamIds); 138 void StartCapture(int streamId, int captureId, bool shutterCallback, bool isStreaming); 139 float calTime(struct timeval start, struct timeval end); 140 }; 141 #endif