diff --git a/services/dfx/BUILD.gn b/services/dfx/BUILD.gn index a0864bb86d79b27f48deeb64373f9573f03a9278..2328df07cd374b17abbb8e963c75ec854b783b13 100644 --- a/services/dfx/BUILD.gn +++ b/services/dfx/BUILD.gn @@ -26,7 +26,6 @@ ohos_shared_library("av_codec_service_dfx") { sanitize = av_codec_sanitize sources = [ - "avcodec_bitstream_dump.cpp", "avcodec_dump_utils.cpp", "avcodec_sysevent.cpp", "avcodec_trace.cpp", diff --git a/services/dfx/avcodec_bitstream_dump.cpp b/services/dfx/avcodec_bitstream_dump.cpp deleted file mode 100644 index fd76d4295818965142450b536feb592c29a15d38..0000000000000000000000000000000000000000 --- a/services/dfx/avcodec_bitstream_dump.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (C) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "avcodec_bitstream_dump.h" -#include -#include -#include -#include -#include -#include -#include -#include "avcodec_log.h" - -namespace { - constexpr ::OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_FRAMEWORK, "AVCodecBitStreamDumper"}; - constexpr int32_t FILE_MAX = 100; - constexpr int32_t FILE_BIT_STREAM_MAX = 1000; - constexpr uint8_t HEX_WIDTH = 2; - - const std::map BIT_STREAM_DUMP_MAP = { - { OHOS::MediaAVCodec::BitStreamDumpType::BIT_STREAM_DUMP_TYPE_DEFAULT, "Default" }, - { OHOS::MediaAVCodec::BitStreamDumpType::BIT_STREAM_DUMP_TYPE_VCODEC, "Video_Codec" }, - { OHOS::MediaAVCodec::BitStreamDumpType::BIT_STREAM_DUMP_TYPE_ACODEC, "Audio_Codec" }, - { OHOS::MediaAVCodec::BitStreamDumpType::BIT_STREAM_DUMP_TYPE_MUXER, "Muxer" }, - { OHOS::MediaAVCodec::BitStreamDumpType::BIT_STREAM_DUMP_TYPE_DEMUXER, "Demuxer" }, - { OHOS::MediaAVCodec::BitStreamDumpType::BIT_STREAM_DUMP_TYPE_SOURCE, "Source" }, - }; -} - -namespace OHOS { -namespace MediaAVCodec { -AVCodecBitStreamDumper &AVCodecBitStreamDumper::GetInstance() -{ - static AVCodecBitStreamDumper avcodecBitStreamDumper; - return avcodecBitStreamDumper; -} - -AVCodecBitStreamDumper::AVCodecBitStreamDumper() {} - -AVCodecBitStreamDumper::~AVCodecBitStreamDumper() -{ - { - std::unique_lock lock(mutex_); - isExit_ = true; - cond_.notify_all(); - } - if (thread_ != nullptr && thread_->joinable()) { - thread_->join(); - } -} - -static void AddNewBitStream(BitStreamDumpType type, const std::string &name, - const uint32_t index, const uint32_t size, std::string &bitstreamStr) -{ - struct timeval time = {}; - (void)gettimeofday(&time, nullptr); - int64_t second = time.tv_sec % 60; - int64_t allMinute = time.tv_sec / 60; - int64_t minute = allMinute % 60; - int64_t hour = allMinute / 60 % 24; - int64_t mSecond = time.tv_usec / 1000; - - std::stringstream outStream; - outStream << "### "; - outStream << "[" << BIT_STREAM_DUMP_MAP.at(type).data() << "] "; - outStream << "[" << name << "] "; - outStream << "[" << "Index: " << std::to_string(index) << "] "; - outStream << "[" << "Size: " << std::to_string(size) << "] "; - outStream << "[" << std::to_string(hour) << ":" << std::to_string(minute) << ":" << std::to_string(second) << - "." << std::to_string(mSecond) << "] "; - outStream << "[" << "pid: " << std::to_string(getpid()) << "] "; - outStream << "[" << "tid: " << std::to_string(gettid()) << "] "; - outStream << "[" << "uid: " << std::to_string(getuid()) << "] "; - outStream << std::endl; - - bitstreamStr += outStream.str(); -} - -void AVCodecBitStreamDumper::SaveBitStream(BitStreamDumpType type, const std::string &name, - const uint32_t index, const uint8_t* buffer, const uint32_t size) -{ - std::unique_lock lock(mutex_); - if (!isEnable_) { - if (thread_ != nullptr) { - AVCODEC_LOGI("Bitstream dumper shutdown."); - thread_.reset(); - } - return; - } - - if (thread_ == nullptr) { - AVCODEC_LOGI("Bitstream dumper init"); - thread_ = std::make_unique(&AVCodecBitStreamDumper::TaskProcessor, this); - } - - std::stringstream outStream; - outStream << std::hex << std::uppercase << std::setfill('0'); - for (uint32_t idx = 0; idx < size; idx++) { - outStream << std::setw(HEX_WIDTH) << (int)(buffer[idx]) << " "; - } - - AddNewBitStream(type, name, index, size, bitstreamString_); - - bitstreamString_ += outStream.str(); - bitstreamString_ += "\n\n"; - - isDump_ = true; - - bitStreamCount_++; - if (bitStreamCount_ >= FILE_BIT_STREAM_MAX) { - cond_.notify_all(); - } -} - -bool AVCodecBitStreamDumper::SwitchEnable() -{ - isEnable_ = !isEnable_; - std::string status = isEnable_ ? "Enable" : "Disable"; - AVCODEC_LOGI("Bitstream dumper on status: %{public}s", status.c_str()); - return isEnable_; -} - -void AVCodecBitStreamDumper::TaskProcessor() -{ - pthread_setname_np(pthread_self(), "AVCodecBitStreamDumperTask"); - (void)mallopt(M_SET_THREAD_CACHE, M_THREAD_CACHE_DISABLE); - (void)mallopt(M_DELAYED_FREE, M_DELAYED_FREE_DISABLE); - while (true) { - std::string temp; - int32_t lineCount = 0; - { - std::unique_lock lock(mutex_); - if (isExit_) { - return; - } - static constexpr int32_t timeout = 5; // every 5 second have a log - cond_.wait_for(lock, std::chrono::seconds(timeout), - [this] { - return isExit_ || isDump_ || bitStreamCount_ >= FILE_BIT_STREAM_MAX || !bitstreamString_.empty(); - }); - isDump_ = false; - lineCount = bitStreamCount_; - bitStreamCount_ = bitStreamCount_ >= FILE_BIT_STREAM_MAX ? 0 : bitStreamCount_; - swap(bitstreamString_, temp); - } - - std::string file = "/data/media/av_codec/bitstream_dump/"; - file += std::to_string(getpid()); - file += "_bitstream_dump_"; - file += std::to_string(fileCount_) + ".log"; - - std::ofstream ofStream; - if (isNewFile_) { - ofStream.open(file, std::ios::out | std::ios::trunc); - } else { - ofStream.open(file, std::ios::out | std::ios::app); - } - if (!ofStream.is_open()) { - AVCODEC_LOGE("Open bitstream dump file failed"); - continue; - } - isNewFile_ = false; - if (lineCount >= FILE_BIT_STREAM_MAX) { - isNewFile_ = true; - fileCount_++; - fileCount_ = fileCount_ > FILE_MAX ? 0 : fileCount_; - } - - AVCODEC_LOGI("Save bitstream"); - ofStream.write(temp.c_str(), temp.size()); - ofStream.close(); - } -} -} // namespace MediaAVCodec -} // namespace OHOS \ No newline at end of file diff --git a/services/dfx/avcodec_dump_utils.cpp b/services/dfx/avcodec_dump_utils.cpp index 8fca479300ce513d0f9b03449e72ad106d4b35a1..689e4e14ee74c80e81c460400e8f4c28723ed4eb 100644 --- a/services/dfx/avcodec_dump_utils.cpp +++ b/services/dfx/avcodec_dump_utils.cpp @@ -42,7 +42,7 @@ int32_t AVCodecDumpControler::AddInfo(const uint32_t dumpIdx, const std::string return AVCS_ERR_OK; } - int32_t level = GetLevel(dumpIdx); + auto level = GetLevel(dumpIdx); length_[level - 1] = length_[level - 1] > name.length() ? length_[level - 1] : name.length(); dumpInfoMap_.emplace(dumpIdx, make_pair(name, value)); return AVCS_ERR_OK; @@ -116,7 +116,7 @@ int32_t AVCodecDumpControler::AddInfoFromFormatWithMapping(const uint32_t dumpId int32_t AVCodecDumpControler::GetDumpString(std::string &dumpString) { for (auto iter : dumpInfoMap_) { - int level = GetLevel(iter.first); + auto level = GetLevel(iter.first); std::string name = iter.second.first; std::string value = iter.second.second; dumpString += std::string((level - 1) * DUMP_SPACE_LENGTH, ' ') @@ -131,7 +131,7 @@ int32_t AVCodecDumpControler::GetDumpString(std::string &dumpString) uint32_t AVCodecDumpControler::GetLevel(const uint32_t dumpIdx) { - int level = 1; + uint32_t level = 1; if (dumpIdx & UINT8_MAX) { level = DUMP_LEVEL_4; } else if ((dumpIdx >> DUMP_OFFSET_8) & UINT8_MAX) { diff --git a/services/dfx/include/avcodec_bitstream_dump.h b/services/dfx/include/avcodec_bitstream_dump.h deleted file mode 100644 index 558af7b083701ae8f2f34f2275f5fd969454dfd1..0000000000000000000000000000000000000000 --- a/services/dfx/include/avcodec_bitstream_dump.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AVCODEC_BITSTREAM_DUMP_H -#define AVCODEC_BITSTREAM_DUMP_H - -#include -#include -#include -#include - -namespace OHOS { -namespace MediaAVCodec { -enum class BitStreamDumpType { - BIT_STREAM_DUMP_TYPE_DEFAULT, - BIT_STREAM_DUMP_TYPE_VCODEC, - BIT_STREAM_DUMP_TYPE_ACODEC, - BIT_STREAM_DUMP_TYPE_MUXER, - BIT_STREAM_DUMP_TYPE_DEMUXER, - BIT_STREAM_DUMP_TYPE_SOURCE -}; - -class __attribute__((visibility("default"))) AVCodecBitStreamDumper { -public: - static AVCodecBitStreamDumper &GetInstance(); - void SaveBitStream(BitStreamDumpType type, const std::string &name, - const uint32_t index, const uint8_t* buffer, const uint32_t size); - bool SwitchEnable(); - -private: - AVCodecBitStreamDumper(); - ~AVCodecBitStreamDumper(); - int32_t fileCount_ = 0; - int32_t bitStreamCount_ = 0; - std::unique_ptr thread_; - void TaskProcessor(); - std::mutex mutex_; - std::condition_variable cond_; - std::string bitstreamString_; - bool isDump_ = false; - bool isExit_ = false; - bool isEnable_ = false; - bool isNewFile_ = true; -}; - -// AVCodec bitstream dump macro interface -#ifdef BITSTREAM_DUMP_ENABLE -#define AVCODEC_BITSTREAM_DUMP(type, name, index, buffer, size) \ - do { \ - (void)OHOS::MediaAVCodec::AVCodecBitStreamDumper::GetInstance().SaveBitStream( \ - type, name, index, buffer, size); \ - } while (0) -#else -#define AVCODEC_BITSTREAM_DUMP(type, name, index, buffer, size) -#endif -} // namespace MediaAVCodec -} // namespace OHOS - -#endif // AVCODEC_LOG_DUMP_H \ No newline at end of file diff --git a/services/services/codec/server/codec_param_checker.cpp b/services/services/codec/server/codec_param_checker.cpp index 11fa02e22a15b359d1c42723732103ce902726ba..decbb7de0af65de4462703881754267418430930 100644 --- a/services/services/codec/server/codec_param_checker.cpp +++ b/services/services/codec/server/codec_param_checker.cpp @@ -318,7 +318,7 @@ int32_t QPChecker(CapabilityData &capData, Format &format, AVCodecType codecType if (!qpMinExist && !qpMaxExist) { return AVCS_ERR_OK; } - CHECK_AND_RETURN_RET_LOG(!(qpMinExist ^ qpMaxExist), AVCS_ERR_INVALID_VAL, + CHECK_AND_RETURN_RET_LOG(!(qpMinExist != qpMaxExist), AVCS_ERR_INVALID_VAL, "Param invalid, QPmin and QPmax are expected to be set in pairs in format"); CHECK_AND_RETURN_RET_LOG(qpMin >= 0 && qpMin <= qpMax, AVCS_ERR_INVALID_VAL, diff --git a/services/services/sa_avcodec/server/avcodec_server_manager.cpp b/services/services/sa_avcodec/server/avcodec_server_manager.cpp index 42efaab4b22ecd0297ab47ea9dc7ee80b33f72d3..e6c4f6752cc942f55884b3deb5f230d7ec3e3cb8 100644 --- a/services/services/sa_avcodec/server/avcodec_server_manager.cpp +++ b/services/services/sa_avcodec/server/avcodec_server_manager.cpp @@ -23,7 +23,6 @@ #include "avcodec_log.h" #include "avcodec_xcollie.h" #include "avcodec_dump_utils.h" -#include "avcodec_bitstream_dump.h" #ifdef SUPPORT_CODEC #include "codec_service_stub.h" #endif @@ -40,7 +39,7 @@ constexpr uint32_t DUMP_UID_INDEX = 0x01010200; constexpr uint32_t DUMP_OFFSET_16 = 16; const std::vector SA_DUMP_MENU_DUMP_TABLE = { - "All", "Codec", " ", "Switch_bitstream_dump" + "All", "Codec" }; const std::map STUB_TYPE_STRING_MAP = { @@ -124,16 +123,6 @@ int32_t AVCodecServerManager::Dump(int32_t fd, const std::vector PrintDumpMenu(fd); } - if (argSets.find(u"Switch_bitstream_dump") != argSets.end()) { - dumpString += "[Bitstream_Dump]\n"; - bool isEnable = AVCodecBitStreamDumper::GetInstance().SwitchEnable(); - dumpString += " status - "; - dumpString += isEnable ? "Enable" : "Disable"; - dumpString += "\n"; - - WriteFd(fd, dumpString); - } - return OHOS::NO_ERROR; }