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 AVCODEC_LOG_DUMP_H 17 #define AVCODEC_LOG_DUMP_H 18 19 #include <string> 20 #include <thread> 21 #include <mutex> 22 23 namespace OHOS { 24 namespace MediaAVCodec { 25 class __attribute__((visibility("default"))) AVCodecLogDump { 26 public: 27 static AVCodecLogDump &GetInstance(); 28 void SaveLog(const char *fmt, ...); 29 30 private: 31 AVCodecLogDump(); 32 ~AVCodecLogDump(); 33 void UpdateCheckEnable(); 34 int32_t fileCount_ = 0; 35 int32_t lineCount_ = 0; 36 std::unique_ptr<std::thread> thread_; 37 void TaskProcessor(); 38 std::mutex mutex_; 39 std::condition_variable cond_; 40 std::string logString_; 41 bool isDump_ = false; 42 bool isExit_ = false; 43 bool isEnable_ = false; 44 bool isNewFile_ = true; 45 }; 46 47 // AVCodec log dump macro interface 48 #ifdef OHOS_MEDIA_AVCODEC_LOG_DUMP 49 #define AVCODEC_DUMP_LOG(fmt, args...) \ 50 do { \ 51 (void)OHOS::MediaAVCodec::AVCodecLogDump::GetInstance().SaveLog( \ 52 "{%s():%d} " fmt, __FUNCTION__, __LINE__, ##args); \ 53 } while (0) 54 #else 55 #define AVCODEC_DUMP_LOG(fmt, args...) 56 #endif 57 } // namespace MediaAVCodec 58 } // namespace OHOS 59 60 #endif // AVCODEC_LOG_DUMP_H