• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 HDI_CAMERA_DUMP_H
17 #define HDI_CAMERA_DUMP_H
18 
19 #include <string>
20 #include <map>
21 #include <thread>
22 #include <mutex>
23 #include <condition_variable>
24 #include "camera_metadata_operator.h"
25 #include "camera_metadata_info.h"
26 #include "devhost_dump_reg.h"
27 #include "hdf_sbuf.h"
28 #include "ibuffer.h"
29 #include <iostream>
30 
31 namespace OHOS::Camera {
32 enum DumpType {
33     MedataType,
34     BufferType,
35     OpenType
36 };
37 
38 const std::string ENABLE_DQ_BUFFER_DUMP = "enableDQBufDump";
39 const std::string ENABLE_UVC_NODE = "enableUVCNodeBufferDump";
40 const std::string ENABLE_UVC_NODE_CONVERTED = "enableUVCNodeConvertedBufferDump";
41 const std::string ENABLE_EXIF_NODE_CONVERTED = "enableExifNodeConvertedBufferDump";
42 const std::string ENABLE_FACE_NODE_CONVERTED = "enableFaceNodeConvertedBufferDump";
43 const std::string ENABLE_FORK_NODE_CONVERTED = "enableForkNodeConvertedBufferDump";
44 const std::string ENABLE_RKFACE_NODE_CONVERTED = "enableRKFaceNodeConvertedBufferDump";
45 const std::string ENABLE_RKEXIF_NODE_CONVERTED = "enableRKExifNodeConvertedBufferDump";
46 const std::string ENABLE_CODEC_NODE_CONVERTED = "enableCodecNodeConvertedBufferDump";
47 const std::string ENABLE_RKCODEC_NODE_CONVERTED = "enableRKCodecNodeConvertedBufferDump";
48 const std::string ENABLE_STREAM_TUNNEL = "enableSreamTunnelBufferDump";
49 const std::string ENABLE_METADATA = "enableMetadataDump";
50 const std::string PREVIEW_INTERVAL = "previewInterval";
51 const std::string CAPTURE_INTERVAL = "captureInterval";
52 
53 class CameraDumper {
54 public:
55     ~CameraDumper ();
56     bool DumpBuffer(std::string name, std::string type, const std::shared_ptr<IBuffer>& buffer);
57     bool DumpStart();
58     bool ReadDumpConfig();
59     bool IsDumpCommandOpened(std::string type);
60     bool DumpMetadata(std::string name, std::string type, const std::shared_ptr<CameraMetadata>& metadata);
61     void ShowDumpMenu(struct HdfSBuf *reply);
62     void CameraHostDumpProcess(struct HdfSBuf *data, struct HdfSBuf *reply);
63     static CameraDumper& GetInstance();
64 
65 private:
CameraDumper()66     CameraDumper() {}
67     bool IsDumpOpened(DumpType type);
68     uint64_t GetCurrentLocalTimeStamp();
69     void UpdateDumpMode(DumpType type, bool isDump, struct HdfSBuf *reply);
70     bool SaveDataToFile(const char *fileName, const void *data, uint32_t size);
71     void CheckDiskInfo();
72     void ThreadWorkFun();
73     void StartCheckDiskInfo();
74     void StopCheckDiskInfo();
75 
76 private:
77     std::mutex dumpStateLock_;
78     std::condition_variable cv_;
79     std::mutex terminateLock_;
80     bool terminate_ = true;
81     std::unique_ptr<std::thread> handleThread_ = nullptr;
82     int32_t dumpCount_ = 0;
83 };
84 
85 int32_t CameraDumpEvent(struct HdfSBuf *data, struct HdfSBuf *reply);
86 
87 } // OHOS::Camera
88 
89 #endif // HDI_CAMERA_DUMP_H
90