Skip to content

Commit

Permalink
1st attempt to use wfb-cli msgpack socket
Browse files Browse the repository at this point in the history
  • Loading branch information
seriyps committed Nov 16, 2024
1 parent 94e3606 commit ec86d81
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ jobs:
tee /etc/apt/sources.list.d/70-radxa.list <<< "deb [signed-by=/usr/share/keyrings/radxa-archive-keyring.gpg] https://radxa-repo.github.io/bullseye/ bullseye main"
tee /etc/apt/sources.list.d/80-rockchip.list <<< "deb [signed-by=/usr/share/keyrings/radxa-archive-keyring.gpg] https://radxa-repo.github.io/bullseye rockchip-bullseye main"
rm -r /boot/* #save space
apt-get update
apt-get install -y cmake g++ git pkg-config librockchip-mpp-dev libcairo-dev libdrm-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libspdlog-dev nlohmann-json3-dev
apt clean
apt-get install -y cmake g++ git pkg-config librockchip-mpp-dev libcairo-dev libdrm-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libspdlog-dev nlohmann-json3-dev libmsgpack-dev
apt clean
cmake -B build
Expand Down
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,24 @@ set(SOURCE_FILES
src/mavlink.c
src/main.cpp
src/main.h
src/wfbcli.hpp
src/wfbcli.cpp
src/scheduling_helper.hpp
src/gstrtpreceiver.cpp
src/gstrtpreceiver.h)
file(GLOB ICONS src/icons/*.png)
file(GLOB OSD_CONFIGS *_osd.json)

include_directories("/usr/include/libdrm" "/usr/include/cairo" "/usr/include/spdlog")
include_directories("/usr/include/libdrm" "/usr/include/cairo" "/usr/include/spdlog" "/usr/include/msgpack")

configure_file("${PROJECT_NAME}_config.h.in" "${PROJECT_NAME}_config.h")

find_package(spdlog REQUIRED)
find_package(nlohmann_json 3 REQUIRED)
#find_package(msgpack REQUIRED) # called msgpack-c in Ubunty

add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} rockchip_mpp pthread drm m cairo spdlog::spdlog nlohmann_json::nlohmann_json)
target_link_libraries(${PROJECT_NAME} rockchip_mpp pthread drm m cairo spdlog::spdlog nlohmann_json::nlohmann_json) # msgpack)

# Embed gstreamer
find_package(PkgConfig REQUIRED)
Expand Down
11 changes: 10 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extern "C" {

#include "osd.h"
#include "osd.hpp"
#include "wfbcli.hpp"
#include "dvr.h"
#include "gstrtpreceiver.h"
#include "scheduling_helper.hpp"
Expand Down Expand Up @@ -353,6 +354,7 @@ void sig_handler(int signum)
spdlog::info("Received signal {}", signum);
signal_flag++;
mavlink_thread_signal++;
wfb_thread_signal++;
osd_thread_signal++;
if (dvr != NULL) {
dvr->shutdown();
Expand Down Expand Up @@ -772,7 +774,7 @@ int main(int argc, char **argv)
ret = pthread_cond_init(&video_cond, NULL);
assert(!ret);

pthread_t tid_frame, tid_display, tid_osd, tid_mavlink, tid_dvr;
pthread_t tid_frame, tid_display, tid_osd, tid_mavlink, tid_dvr, tid_wfbcli;
if (dvr_template != NULL) {
dvr_thread_params args;
args.filename_template = dvr_template;
Expand Down Expand Up @@ -803,6 +805,11 @@ int main(int argc, char **argv)
ret = pthread_create(&tid_mavlink, NULL, __MAVLINK_THREAD__, &signal_flag);
assert(!ret);
}
wfb_thread_params *wfb_args = (wfb_thread_params *)malloc(sizeof *wfb_args);
wfb_args->port = 8003; // TODO: configurable
ret = pthread_create(&tid_wfbcli, NULL, __WFB_CLI_THREAD__, wfb_args);
assert(!ret);

osd_thread_params *args = (osd_thread_params *)malloc(sizeof *args);
args->fd = drm_fd;
args->out = output_list;
Expand Down Expand Up @@ -839,6 +846,8 @@ int main(int argc, char **argv)
assert(!ret);
}
if (enable_osd) {
ret = pthread_join(tid_wfbcli, NULL);
assert(!ret);
ret = pthread_join(tid_osd, NULL);
assert(!ret);
}
Expand Down
4 changes: 2 additions & 2 deletions src/osd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ void osd_add_double_fact(void *batch, char const *name, osd_tag *tags, int n_tag
facts->push_back(Fact(FactMeta(std::string(name), fact_tags), value));
};

void osd_add_str_fact(void *batch, char const *name, osd_tag *tags, int n_tags, char *value) {
void osd_add_str_fact(void *batch, char const *name, osd_tag *tags, int n_tags, const char *value) {
std::vector<Fact> *facts = static_cast<std::vector<Fact> *>(batch);
FactTags fact_tags;
mk_tags(tags, n_tags, &fact_tags);
Expand Down Expand Up @@ -1650,7 +1650,7 @@ void osd_publish_double_fact(char const *name, osd_tag *tags, int n_tags, double
publish(Fact(FactMeta(std::string(name), fact_tags), value));
};

void osd_publish_str_fact(char const *name, osd_tag *tags, int n_tags, char *value) {
void osd_publish_str_fact(char const *name, osd_tag *tags, int n_tags, const char *value) {
FactTags fact_tags;
mk_tags(tags, n_tags, &fact_tags);
publish(Fact(FactMeta(std::string(name), fact_tags), std::string(value)));
Expand Down
4 changes: 2 additions & 2 deletions src/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ void osd_add_bool_fact(void *batch, char const *name, osd_tag *tags, int n_tags,
void osd_add_int_fact(void *batch, char const *name, osd_tag *tags, int n_tags, long value);
void osd_add_uint_fact(void *batch, char const *name, osd_tag *tags, int n_tags, ulong value);
void osd_add_double_fact(void *batch, char const *name, osd_tag *tags, int n_tags, double value);
void osd_add_str_fact(void *batch, char const *name, osd_tag *tags, int n_tags, char *value);
void osd_add_str_fact(void *batch, char const *name, osd_tag *tags, int n_tags, const char *value);

// Publish individual facts
void osd_publish_bool_fact(char const *name, osd_tag *tags, int n_tags, bool value);
void osd_publish_int_fact(char const *name, osd_tag *tags, int n_tags, long value);
void osd_publish_uint_fact(char const *name, osd_tag *tags, int n_tags, ulong value);
void osd_publish_double_fact(char const *name, osd_tag *tags, int n_tags, double value);
void osd_publish_str_fact(char const *name, osd_tag *tags, int n_tags, char *value);
void osd_publish_str_fact(char const *name, osd_tag *tags, int n_tags, const char *value);
#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit ec86d81

Please sign in to comment.