11c1b0f19Sopenharmony_ci/*
21c1b0f19Sopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
31c1b0f19Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
41c1b0f19Sopenharmony_ci * you may not use this file except in compliance with the License.
51c1b0f19Sopenharmony_ci * You may obtain a copy of the License at
61c1b0f19Sopenharmony_ci *
71c1b0f19Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
81c1b0f19Sopenharmony_ci *
91c1b0f19Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
101c1b0f19Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
111c1b0f19Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
121c1b0f19Sopenharmony_ci * See the License for the specific language governing permissions and
131c1b0f19Sopenharmony_ci * limitations under the License.
141c1b0f19Sopenharmony_ci */
151c1b0f19Sopenharmony_ci
161c1b0f19Sopenharmony_ci#ifndef OHOS_DCAMERA_UTILS_TOOL_H
171c1b0f19Sopenharmony_ci#define OHOS_DCAMERA_UTILS_TOOL_H
181c1b0f19Sopenharmony_ci
191c1b0f19Sopenharmony_ci#include <atomic>
201c1b0f19Sopenharmony_ci#include <cstdint>
211c1b0f19Sopenharmony_ci#include <string>
221c1b0f19Sopenharmony_ci#include <fstream>
231c1b0f19Sopenharmony_ci#include <map>
241c1b0f19Sopenharmony_ci#include "single_instance.h"
251c1b0f19Sopenharmony_ci
261c1b0f19Sopenharmony_ci#ifdef DCAMERA_MMAP_RESERVE
271c1b0f19Sopenharmony_ci#include "image_converter.h"
281c1b0f19Sopenharmony_ci#endif
291c1b0f19Sopenharmony_ci
301c1b0f19Sopenharmony_cinamespace OHOS {
311c1b0f19Sopenharmony_cinamespace DistributedHardware {
321c1b0f19Sopenharmony_ciconst std::string BASE_64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
331c1b0f19Sopenharmony_ci
341c1b0f19Sopenharmony_ciint32_t GetLocalDeviceNetworkId(std::string& networkId);
351c1b0f19Sopenharmony_ciint64_t GetNowTimeStampMs();
361c1b0f19Sopenharmony_ciint64_t GetNowTimeStampUs();
371c1b0f19Sopenharmony_ciint32_t GetAlignedHeight(int32_t width);
381c1b0f19Sopenharmony_cistd::string Base64Encode(const unsigned char *toEncode, unsigned int len);
391c1b0f19Sopenharmony_cistd::string Base64Decode(const std::string& basicString);
401c1b0f19Sopenharmony_civoid DumpBufferToFile(std::string fileName, uint8_t *buffer, size_t bufSize);
411c1b0f19Sopenharmony_cibool IsBase64(unsigned char c);
421c1b0f19Sopenharmony_ciint32_t IsUnderDumpMaxSize(std::string fileName);
431c1b0f19Sopenharmony_ci
441c1b0f19Sopenharmony_ci#ifdef DCAMERA_MMAP_RESERVE
451c1b0f19Sopenharmony_ciclass ConverterHandle {
461c1b0f19Sopenharmony_ci    DECLARE_SINGLE_INSTANCE(ConverterHandle);
471c1b0f19Sopenharmony_ci
481c1b0f19Sopenharmony_cipublic:
491c1b0f19Sopenharmony_ci    void InitConverter();
501c1b0f19Sopenharmony_ci    void DeInitConverter();
511c1b0f19Sopenharmony_ci    const OHOS::OpenSourceLibyuv::ImageConverter &GetHandle();
521c1b0f19Sopenharmony_ci
531c1b0f19Sopenharmony_ci    using DlHandle = void *;
541c1b0f19Sopenharmony_ciprivate:
551c1b0f19Sopenharmony_ci    std::atomic<bool> isInited_ = false;
561c1b0f19Sopenharmony_ci    DlHandle dlHandler_ = nullptr;
571c1b0f19Sopenharmony_ci    OHOS::OpenSourceLibyuv::ImageConverter converter_ = {0};
581c1b0f19Sopenharmony_ci};
591c1b0f19Sopenharmony_ci#endif
601c1b0f19Sopenharmony_ci
611c1b0f19Sopenharmony_ciconst std::string DUMP_SERVER_PARA = "sys.dcamera.dump.write.enable";
621c1b0f19Sopenharmony_ciconst std::string DUMP_SERVICE_DIR = "/data/local/tmp/";
631c1b0f19Sopenharmony_ciconst std::string DUMP_DCAMERA_AFTER_ENC_FILENAME = "dump_after_enc_dcamsink.h265";
641c1b0f19Sopenharmony_ciconst std::string DUMP_DCAMERA_BEFORE_DEC_FILENAME = "dump_before_dec_dcamsource.h265";
651c1b0f19Sopenharmony_ciconst std::string DUMP_DCAMERA_AFTER_DEC_FILENAME = "dump_after_dec_dcamsource.yuv";
661c1b0f19Sopenharmony_ciconst std::string DUMP_DCAMERA_AFTER_SCALE_FILENAME = "dump_after_scale_dcamsource.yuv";
671c1b0f19Sopenharmony_ci
681c1b0f19Sopenharmony_ciclass DumpFileUtil {
691c1b0f19Sopenharmony_cipublic:
701c1b0f19Sopenharmony_ci    static void WriteDumpFile(FILE *dumpFile, void *buffer, size_t bufferSize);
711c1b0f19Sopenharmony_ci    static void CloseDumpFile(FILE **dumpFile);
721c1b0f19Sopenharmony_ci    static std::map<std::string, std::string> g_lastPara;
731c1b0f19Sopenharmony_ci    static void OpenDumpFile(std::string para, std::string fileName, FILE **file);
741c1b0f19Sopenharmony_ciprivate:
751c1b0f19Sopenharmony_ci    static FILE *OpenDumpFileInner(std::string para, std::string fileName);
761c1b0f19Sopenharmony_ci    static void ChangeDumpFileState(std::string para, FILE **dumpFile, std::string fileName);
771c1b0f19Sopenharmony_ci};
781c1b0f19Sopenharmony_ci
791c1b0f19Sopenharmony_ciclass ManageSelectChannel {
801c1b0f19Sopenharmony_ciDECLARE_SINGLE_INSTANCE(ManageSelectChannel);
811c1b0f19Sopenharmony_ci
821c1b0f19Sopenharmony_cipublic:
831c1b0f19Sopenharmony_ci    void SetSrcConnect(bool isSoftbusConnect);
841c1b0f19Sopenharmony_ci    void SetSinkConnect(bool isSoftbusConnect);
851c1b0f19Sopenharmony_ci    bool GetSrcConnect();
861c1b0f19Sopenharmony_ci    bool GetSinkConnect();
871c1b0f19Sopenharmony_ciprivate:
881c1b0f19Sopenharmony_ci    bool isSoftbusConnectSource_ = false;
891c1b0f19Sopenharmony_ci    bool isSoftbusConnectSink_ = false;
901c1b0f19Sopenharmony_ci};
911c1b0f19Sopenharmony_ci} // namespace DistributedHardware
921c1b0f19Sopenharmony_ci} // namespace OHOS
931c1b0f19Sopenharmony_ci#endif // OHOS_DCAMERA_UTILS_TOOL_H
94