Skip to content

Commit

Permalink
* fix module callback in cpp
Browse files Browse the repository at this point in the history
* update .gitignore

* fix cpp_transcode callback case

fix cpp_transcode.cpp

fix cpp_file_check parameter

change the value of bitrate check
  • Loading branch information
JackLau1222 committed Jan 4, 2025
1 parent 7d29ce1 commit 66c01fc
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 49 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
*.so
*.sym
/build*/
CMakeFiles
_deps
bmf/files*
bmf/demo/transcode/*.mp4
bmf/test/distributed_node/build/*
bmf/demo/transcode/*.json
bmf/demo/transcode/test_cb
bmf/demo/transcode/test_cb.d*
!build.gradle
bmf/c_module_sdk/build
bmf/c_module_sdk/cmake-build-debug
Expand Down
6 changes: 6 additions & 0 deletions bmf/engine/connector/include/builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ class RealNode : public std::enable_shared_from_this<RealNode> {

void AddCallback(long long key, bmf::BMFCallback callbackInstance);

void AddCallback(long long key,
std::function<bmf_sdk::CBytes(bmf_sdk::CBytes)> callback);

nlohmann::json Dump();

std::shared_ptr<RealNode>
Expand Down Expand Up @@ -451,6 +454,9 @@ class BMF_ENGINE_API Node {
void AddCallback(long long key,
const bmf::BMFCallback &callbackInstance);

void AddCallback(long long key,
std::function<bmf_sdk::CBytes(bmf_sdk::CBytes)> callback);

void Start();

Node Module(
Expand Down
19 changes: 17 additions & 2 deletions bmf/engine/connector/src/builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,12 @@ nlohmann::json RealNode::NodeMetaInfo::Dump() {
nlohmann::json info;

info["premodule_id"] = preModuleUID_;
info["callback_bindings"] = nlohmann::json::object();
info["callback_binding"] =
nlohmann::json(std::vector<std::string>());
for (auto &kv : callbackBinding_) {
info["callback_bindings"][kv.first] = kv.second;
info["callback_binding"].push_back(
std::to_string(kv.first) + ":" + std::to_string(kv.second)
);
}

return info;
Expand Down Expand Up @@ -228,6 +231,12 @@ void RealNode::AddCallback(long long key, bmf::BMFCallback callbackInstance) {
std::make_shared<bmf::BMFCallback>(callbackInstance);
metaInfo_.callbackBinding_[key] = callbackInstance.uid();
}
void RealNode::AddCallback(long long key, std::function<bmf_sdk::CBytes(bmf_sdk::CBytes)> callback) {
auto cb = bmf::BMFCallback(callback);
metaInfo_.callbackInstances_[key] =
std::make_shared<bmf::BMFCallback>(cb);
metaInfo_.callbackBinding_[key] = cb.uid();
}

std::shared_ptr<RealNode>
RealNode::AddModule(std::string const &alias, const bmf_sdk::JsonParam &option,
Expand Down Expand Up @@ -666,6 +675,12 @@ void Node::AddCallback(long long key,
baseP_->AddCallback(key, callbackInstance);
}

void Node::AddCallback(long long key,
std::function<bmf_sdk::CBytes(bmf_sdk::CBytes)> callback) {
std::cout << "===CallBack==== Node::AddCallback" << &callback << std::endl;
baseP_->AddCallback(key, callback);
}

void Node::Start() { Stream(0).Start(); }

Node Node::Module(const std::vector<class Stream> &inStreams,
Expand Down
93 changes: 46 additions & 47 deletions bmf/test/cpp_builder/cpp_transcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,53 +318,52 @@ TEST(cpp_transcode, transcode_with_null_audio) {
" \"30.0662251656\"}");
}

// TEST(cpp_transcode, transcode_cb) {
// std::string output_file = "./cb.mp4";
// BMF_CPP_FILE_REMOVE(output_file);

// 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));
// nlohmann::json encode_para = {
// {"output_path", output_file},
// {"video_params", {
// {"codec", "h264"},
// {"width", 320},
// {"height", 240},
// {"crf", 23},
// {"preset", "veryfast"}
// }},
// {"audio_params", {
// {"codec", "aac"},
// {"bit_rate", 128000},
// {"sample_rate", 44100},
// {"channels", 2}
// }}
// };
// auto cb = [](void *, BMFCBytes) -> BMFCBytes {
// BMFLOG(BMF_INFO) << "test cb cpp";
// uint8_t bytes[] = {97, 98, 99, 100, 101, 0};
// return BMFCBytes{bytes, 6};
// };
// BMFCallbackInstance cb_ = nullptr;
// create_callback(cb, nullptr, &cb_);
// graph.Encode(video["video"], video["audio"],
// bmf_sdk::JsonParam(encode_para)).AddCallback(0, *cb_);
// //std::cout << testing::internal::GetCapturedStdout();
// graph.Run();
// BMF_CPP_FILE_CHECK(
// output_file,
// "../transcode/cb.mp4|240|320|7.615000|MOV,MP4,M4A,3GP,3G2,MJ2|366635|348991|h264|{\"fps\":
// \"30.0662251656\"}"
// );
// }
TEST(cpp_transcode, transcode_cb) {
std::string output_file = "./cb.mp4";
BMF_CPP_FILE_REMOVE(output_file);

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));
nlohmann::json encode_para = {
{"output_path", output_file},
{"video_params", {
{"codec", "h264"},
{"width", 320},
{"height", 240},
{"crf", 23},
{"preset", "veryfast"}
}},
{"audio_params", {
{"codec", "aac"},
{"bit_rate", 128000},
{"sample_rate", 44100},
{"channels", 2}
}}
};

auto callback = [](bmf_sdk::CBytes input) -> bmf_sdk::CBytes {
std::string strInfo;
strInfo.assign(reinterpret_cast<const char*>(input.buffer), input.size);
BMFLOG(BMF_INFO) << "====Callback==== " << strInfo;
return bmf_sdk::CBytes{input.buffer, input.size};
};

graph.Encode(video["video"], video["audio"],
bmf_sdk::JsonParam(encode_para)).AddCallback(0, callback);
graph.Run();
BMF_CPP_FILE_CHECK(output_file, "../transcode/"
"cb.mp4|240|320|10.0|MOV,MP4,"
"M4A,3GP,3G2,MJ2|192235|240486|h264|{\"fps\":"
" \"30.0662251656\"}");
}

TEST(cpp_transcode, transcode_hls) {
std::string output_file = "./file000.ts";
Expand Down

0 comments on commit 66c01fc

Please sign in to comment.