转码支持增量和转码信息debug时打印

Signed-off-by: fangyunzhong <fangyunzhong2@huawei.com>
This commit is contained in:
fangyunzhong
2024-06-29 11:11:53 +08:00
parent 80eff902cd
commit e9172e58f4
5 changed files with 51 additions and 6 deletions
+3
View File
@@ -67,6 +67,7 @@ public:
bool GetMediaSwitch();
std::string PrintTransMessage();
bool GetDefaultCompress();
void SetOutPath(const std::string &path);
private:
bool ParseContext(const cJSON *contextNode);
bool ParseCompression(const cJSON *compressionNode);
@@ -88,6 +89,7 @@ private:
std::string GetOptionsString(const std::shared_ptr<CompressFilter> &compressFilter, int type);
bool CheckAndTranscode(const std::string &src, std::string &dst, std::string &output,
const std::shared_ptr<CompressFilter> &compressFilter, const bool extAppend);
bool CopyForTrans(const std::string &src, const std::string &originDst, const std::string &dst);
bool IsDefaultCompress();
std::string filePath_;
std::string extensionPath_;
@@ -95,6 +97,7 @@ private:
bool mediaSwitch_;
cJSON *root_;
bool defaultCompress_;
std::string outPath_;
unsigned long long totalTime_ = 0;
uint32_t totalCounts_ = 0;
unsigned long long compressTime_ = 0;
+1
View File
@@ -27,6 +27,7 @@ namespace Global {
namespace Restool {
const static std::string TOOL_NAME = "restool";
const static std::string RESOURCES_DIR = "resources";
const static std::string CACHES_DIR = ".caches";
const static std::string CONFIG_JSON = "config.json";
const static std::string MODULE_JSON = "module.json";
const static std::string RAW_FILE_DIR = "rawfile";
+45 -5
View File
@@ -46,12 +46,13 @@ const map<TranscodeError, string> ERRORCODEMAP = {
};
CompressionParser::CompressionParser()
: filePath_(""), extensionPath_(""), mediaSwitch_(false), root_(nullptr), defaultCompress_(false)
: filePath_(""), extensionPath_(""), mediaSwitch_(false), root_(nullptr), defaultCompress_(false), outPath_("")
{
}
CompressionParser::CompressionParser(const string &filePath)
: filePath_(filePath), extensionPath_(""), mediaSwitch_(false), root_(nullptr), defaultCompress_(false)
: filePath_(filePath), extensionPath_(""), mediaSwitch_(false), root_(nullptr), defaultCompress_(false),
outPath_("")
{
}
@@ -114,6 +115,12 @@ uint32_t CompressionParser::Init()
if (!LoadImageTranscoder()) {
return RESTOOL_ERROR;
}
string caches = outPath_;
caches.append(SEPARATOR_FILE).append(CACHES_DIR);
if (!ResourceUtil::CreateDirs(caches)) {
cerr << "Error: create caches dir failed. dir = " << caches << endl;
return RESTOOL_ERROR;
}
return RESTOOL_SUCCESS;
}
@@ -233,6 +240,11 @@ bool CompressionParser::IsDefaultCompress()
(compressFilter->rules.size() == 0) && (compressFilter->expandRules.size() == 0);
}
void CompressionParser::SetOutPath(const std::string &path)
{
outPath_ = path;
}
vector<string> CompressionParser::ParseRules(const cJSON *rulesNode)
{
vector<string> res;
@@ -508,6 +520,27 @@ bool CompressionParser::CheckAndTranscode(const string &src, string &dst, string
return false;
}
bool CompressionParser::CopyForTrans(const string &src, const string &originDst, const string &dst)
{
auto srcIndex = src.find_last_of(".");
auto dstIndex = dst.find_last_of(".");
if (srcIndex == string::npos || dstIndex == string::npos) {
cerr << "Error: invalid copy path." << endl;
return false;
}
string srcSuffix = src.substr(srcIndex + 1);
string dstSuffix = dst.substr(dstIndex + 1);
auto ret = false;
if (srcSuffix == dstSuffix) {
ret = ResourceUtil::CopyFileInner(src, dst);
} else {
uint32_t startIndex = outPath_.size() + CACHES_DIR.size() + 1;
string dstPath = outPath_ + SEPARATOR_FILE + RESOURCES_DIR + dst.substr(startIndex);
ret = ResourceUtil::CopyFileInner(dst, dstPath);
}
return ret;
}
bool CompressionParser::CopyAndTranscode(const string &src, string &dst, const bool extAppend)
{
auto t0 = std::chrono::steady_clock::now();
@@ -522,15 +555,22 @@ bool CompressionParser::CopyAndTranscode(const string &src, string &dst, const b
cerr << "Error: invalid output path." << NEW_LINE_PATH << dst << endl;
return false;
}
string output = dst.substr(0, index);
uint32_t startIndex = outPath_.size() + RESOURCES_DIR.size() + 1;
string endStr = dst.substr(startIndex, index - startIndex);
string output = outPath_ + SEPARATOR_FILE + CACHES_DIR + endStr;
string originDst = dst;
if (!ResourceUtil::CreateDirs(output)) {
cerr << "Error: create output dir failed. dir = " << output << endl;
return false;
}
for (const auto &compressFilter : compressFilters_) {
if (!CheckAndTranscode(src, dst, output, compressFilter, extAppend)) {
continue;
}
return true;
break;
}
auto t2 = std::chrono::steady_clock::now();
auto ret = ResourceUtil::CopyFileInner(src, dst);
auto ret = CopyForTrans(src, originDst, dst);
CollectTime(totalCounts_, totalTime_, t2);
return ret;
}
+1
View File
@@ -48,6 +48,7 @@ uint32_t ResourcePack::InitCompression()
{
if (!packageParser_.GetCompressionPath().empty()) {
auto compressionMgr = CompressionParser::GetCompressionParser(packageParser_.GetCompressionPath());
compressionMgr->SetOutPath(packageParser_.GetOutput());
if (compressionMgr->Init() != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
+1 -1
View File
@@ -45,7 +45,7 @@ int main(int argc, char *argv[])
}
cout << "Info: restool resources compile success." << endl;
if (CompressionParser::GetCompressionParser()->GetMediaSwitch()) {
cerr << CompressionParser::GetCompressionParser()->PrintTransMessage() << endl;
cout << CompressionParser::GetCompressionParser()->PrintTransMessage() << endl;
}
return RESTOOL_SUCCESS;
}