-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Don't Merge!!!] Test SonarQube #1
base: master
Are you sure you want to change the base?
Changes from 16 commits
4ca3256
0a39a59
1e1b7ee
62a0009
e239d86
d4a6065
c35f493
8570d37
b907d59
3b25df5
f4cff01
62abfa5
de176bc
5d6c6d4
2b88690
f13ba64
6c195d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,10 @@ | ||||||||||||||||||||||||
#!/bin/bash | ||||||||||||||||||||||||
# set the environment variables for bmf | ||||||||||||||||||||||||
export C_INCLUDE_PATH=${C_INCLUDE_PATH}:$(pwd)/output/bmf/include | ||||||||||||||||||||||||
export CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:$(pwd)/output/bmf/include | ||||||||||||||||||||||||
export LIBRARY_PATH=${LIBRARY_PATH}:$(pwd)/output/bmf/lib | ||||||||||||||||||||||||
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(pwd)/output/bmf/lib | ||||||||||||||||||||||||
Comment on lines
+3
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fix potential masking of return values in export statements. The current inline export assignments could mask return values. Consider separating the declaration and assignment. Apply this diff to fix the issue: -export C_INCLUDE_PATH=${C_INCLUDE_PATH}:$(pwd)/output/bmf/include
-export CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:$(pwd)/output/bmf/include
-export LIBRARY_PATH=${LIBRARY_PATH}:$(pwd)/output/bmf/lib
-export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(pwd)/output/bmf/lib
-export PYTHONPATH=$(pwd)/output/bmf/lib:$(pwd)/output
+C_INCLUDE_PATH=${C_INCLUDE_PATH}:$(pwd)/output/bmf/include
+CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:$(pwd)/output/bmf/include
+LIBRARY_PATH=${LIBRARY_PATH}:$(pwd)/output/bmf/lib
+LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(pwd)/output/bmf/lib
+PYTHONPATH=$(pwd)/output/bmf/lib:$(pwd)/output
+export C_INCLUDE_PATH CPLUS_INCLUDE_PATH LIBRARY_PATH LD_LIBRARY_PATH PYTHONPATH Also applies to: 9-9 🧰 Tools🪛 Shellcheck (0.10.0)[warning] 3-3: Declare and assign separately to avoid masking return values. (SC2155) [warning] 4-4: Declare and assign separately to avoid masking return values. (SC2155) [warning] 5-5: Declare and assign separately to avoid masking return values. (SC2155) [warning] 6-6: Declare and assign separately to avoid masking return values. (SC2155) |
||||||||||||||||||||||||
|
||||||||||||||||||||||||
# only set if you want to use BMF in python | ||||||||||||||||||||||||
export PYTHONPATH=$(pwd)/output/bmf/lib:$(pwd)/output | ||||||||||||||||||||||||
export DYLD_LIBRARY_PATH=~/Documents/Programs/Git/Github/bmf/output/bmf/lib | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove hard-coded path and add directory validation. The script contains a hard-coded path that won't work on other systems. Additionally, the script should validate that required directories exist. Apply this diff to fix the issues: -export DYLD_LIBRARY_PATH=~/Documents/Programs/Git/Github/bmf/output/bmf/lib
+# Check if BMF directories exist
+BMF_OUTPUT_DIR="$(pwd)/output/bmf"
+if [ ! -d "$BMF_OUTPUT_DIR" ]; then
+ echo "Error: BMF output directory not found: $BMF_OUTPUT_DIR"
+ return 1
+fi
+
+# Set DYLD_LIBRARY_PATH relative to current directory
+DYLD_LIBRARY_PATH=${BMF_OUTPUT_DIR}/lib
+export DYLD_LIBRARY_PATH 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
g++ -std=c++17 -g -o test_cb test_cb.cpp -L/Users/jacklau/Documents/Programs/Git/Github/bmf/output/bmf/lib -lengine -lbmf_module_sdk -lhmp |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
#include "builder.hpp" | ||
#include "nlohmann/json.hpp" | ||
#include "connector.hpp" | ||
|
||
#include <regex> | ||
|
||
// Global variable or pass-by-reference as needed | ||
int frame_number_total = 0; | ||
int frame_number_global = 0; | ||
|
||
int process_number = 0; | ||
double rest_time = 0; | ||
|
||
std::chrono::system_clock::time_point last_encoder_call; // Track last call time | ||
bool first_encoder_call = true; // Flag for first call | ||
|
||
Comment on lines
+14
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove or unify duplicate encoder timing variables. -std::chrono::system_clock::time_point last_encoder_call; // Possibly remove
-bool first_encoder_call = true; // Possibly remove
...
static auto last_encoder_call_time = std::chrono::system_clock::now(); Also applies to: 73-73 |
||
std::vector<double> duration_history; // Store recent durations for averaging | ||
constexpr size_t max_history_size = 20; // Limit for the number of durations tracked | ||
constexpr double min_duration_threshold = 10.0; // Ignore durations < 10 ms | ||
|
||
double compute_smooth_duration(double new_duration) { | ||
if (new_duration >= min_duration_threshold) { | ||
duration_history.push_back(new_duration); | ||
if (duration_history.size() > max_history_size) { | ||
duration_history.erase(duration_history.begin()); | ||
} | ||
} | ||
return duration_history.empty() ? 0.0 : | ||
std::accumulate(duration_history.begin(), duration_history.end(), 0.0) / duration_history.size(); | ||
} | ||
|
||
// std::string format_time(const std::tm& tm) { | ||
// char buffer[20]; // Buffer to hold formatted time string | ||
// std::snprintf(buffer, sizeof(buffer), "%04d-%02d-%02d %02d:%02d:%02d", | ||
// tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, | ||
// tm.tm_hour, tm.tm_min, tm.tm_sec); | ||
// return std::string(buffer); | ||
// } | ||
|
||
bmf_sdk::CBytes decoder_callback(bmf_sdk::CBytes input) { | ||
std::string strInfo; | ||
strInfo.assign(reinterpret_cast<const char*>(input.buffer), input.size); | ||
// BMFLOG(BMF_INFO) << "====Callback==== " << strInfo; | ||
|
||
|
||
std::regex frame_regex(R"(\btotal frame number:\s*(\d+))"); | ||
std::smatch match; | ||
|
||
if (std::regex_search(strInfo, match, frame_regex) && match.size() > 1) { | ||
std::istringstream(match[1]) >> frame_number_total; // Convert to int | ||
BMFLOG(BMF_DEBUG) << "Extracted Frame Number: " << frame_number_total; | ||
} else { | ||
BMFLOG(BMF_WARNING) << "Failed to extract frame number"; | ||
} | ||
|
||
uint8_t bytes[] = {97, 98, 99, 100, 101, 0}; | ||
return bmf_sdk::CBytes{bytes, 6}; | ||
} | ||
|
||
bmf_sdk::CBytes encoder_callback(bmf_sdk::CBytes input) { | ||
std::string strInfo; | ||
strInfo.assign(reinterpret_cast<const char*>(input.buffer), input.size); | ||
// BMFLOG(BMF_INFO) << "====Callback==== " << strInfo; | ||
|
||
std::regex frame_regex(R"(\bframe number:\s*(\d+))"); | ||
std::smatch match; | ||
|
||
if (std::regex_search(strInfo, match, frame_regex) && match.size() > 1) { | ||
std::istringstream(match[1]) >> frame_number_global; // Convert to int | ||
BMFLOG(BMF_DEBUG) << "Extracted Total Frame Number: " << frame_number_global; | ||
process_number = frame_number_global * 100 / frame_number_total; | ||
|
||
static auto last_encoder_call_time = std::chrono::system_clock::now(); | ||
auto now = std::chrono::system_clock::now(); | ||
|
||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_encoder_call_time).count(); | ||
last_encoder_call_time = now; | ||
|
||
double smooth_duration = compute_smooth_duration(duration); | ||
if (frame_number_global > 0 && frame_number_total > 0) { | ||
// double progress = static_cast<double>(frame_number_global) / frame_number_total; | ||
rest_time = smooth_duration * (frame_number_total-frame_number_global) / 1000; | ||
} | ||
|
||
BMFLOG(BMF_INFO) << "Process Number (percentage): " << process_number << "%\t" | ||
<< "Current duration (milliseconds): " << duration << "\t" | ||
<< "Smoothed Duration: " << smooth_duration << " ms\t" | ||
<< "Estimated Rest Time (seconds): " << rest_time; | ||
|
||
|
||
|
||
if (frame_number_global == frame_number_total) { | ||
BMFLOG(BMF_INFO) << "====Callback==== Finish"; | ||
} | ||
|
||
} else { | ||
BMFLOG(BMF_WARNING) << "Failed to extract frame number"; | ||
} | ||
|
||
uint8_t bytes[] = {97, 98, 99, 100, 101, 0}; | ||
return bmf_sdk::CBytes{bytes, 6}; | ||
} | ||
|
||
int main() { | ||
std::string output_file = "./cb.mp4"; | ||
|
||
std::function<bmf_sdk::CBytes(bmf_sdk::CBytes)> de_callback = decoder_callback; | ||
std::function<bmf_sdk::CBytes(bmf_sdk::CBytes)> en_callback = encoder_callback; | ||
|
||
nlohmann::json graph_para = { | ||
{"dump_graph", 0} | ||
}; | ||
auto graph = bmf::builder::Graph(bmf::builder::NormalMode, | ||
bmf_sdk::JsonParam(graph_para)); | ||
|
||
nlohmann::json decode_para = { | ||
{"input_path", "../../files/big_bunny_10s_30fps.mp4"}, | ||
}; | ||
auto video = graph.Decode(bmf_sdk::JsonParam(decode_para)); | ||
video.AddCallback(0, std::function<bmf_sdk::CBytes(bmf_sdk::CBytes)>(decoder_callback)); | ||
|
||
nlohmann::json encode_para = { | ||
{"output_path", output_file}, | ||
{"video_params", { | ||
{"codec", "h264"}, | ||
{"crf", 23}, | ||
{"preset", "veryslow"} | ||
}}, | ||
{"audio_params", { | ||
{"codec", "aac"}, | ||
{"bit_rate", 128000}, | ||
{"sample_rate", 44100}, | ||
{"channels", 2} | ||
}} | ||
}; | ||
|
||
|
||
|
||
auto node = graph.Encode(video["video"], video["audio"], | ||
bmf_sdk::JsonParam(encode_para)); | ||
|
||
node.AddCallback(0, en_callback); | ||
|
||
graph.Run(); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security Risk: Remove tmate session before merging.
The tmate session provides SSH access to the CI environment, which could expose sensitive information. This should not be merged into production as it poses a security risk.
Consider using GitHub's built-in debugging features or artifact uploads instead.