Skip to content

Commit

Permalink
Merge pull request #177 from bondagit/make-libfaac-optional
Browse files Browse the repository at this point in the history
Make libfaac optional
  • Loading branch information
bondagit authored Sep 16, 2024
2 parents 3af7dd3 + 1b05763 commit cb27938
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 45 deletions.
7 changes: 7 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[submodule "3rdparty/cpp-httplib"]
path = 3rdparty/cpp-httplib
url = https://github.com/bondagit/cpp-httplib.git
[submodule "3rdparty/ravenna-alsa-lkm"]
path = 3rdparty/ravenna-alsa-lkm
url = https://github.com/bondagit/ravenna-alsa-lkm.git
branch = aes67-daemon
3 changes: 0 additions & 3 deletions 3rdparty/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
/ravenna-alsa-lkm
/cpp-httplib

1 change: 1 addition & 0 deletions 3rdparty/cpp-httplib
Submodule cpp-httplib added at 07c6e5
1 change: 1 addition & 0 deletions 3rdparty/ravenna-alsa-lkm
Submodule ravenna-alsa-lkm added at 989728
20 changes: 6 additions & 14 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,12 @@ export CXX=/usr/bin/clang++

TOPDIR=$(pwd)

cd 3rdparty
if [ ! -d ravenna-alsa-lkm ]; then
git clone --single-branch --branch aes67-daemon https://github.com/bondagit/ravenna-alsa-lkm.git
cd ravenna-alsa-lkm/driver
make
cd ../..
fi
echo "Init git submodules ..."
git submodule update --init --recursive

if [ ! -d cpp-httplib ]; then
git clone https://github.com/bondagit/cpp-httplib.git
cd cpp-httplib
git checkout 42f9f9107f87ad2ee04be117dbbadd621c449552
cd ..
fi
cd ..
cd 3rdparty/ravenna-alsa-lkm/driver
make
cd -

cd webui
echo "Downloading current webui release ..."
Expand All @@ -47,6 +38,7 @@ cmake \
-DWITH_AVAHI=ON \
-DFAKE_DRIVER=OFF \
-DWITH_SYSTEMD=ON \
-DWITH_STREAMER=ON \
.
make
cd ..
Expand Down
15 changes: 2 additions & 13 deletions buildfake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,7 @@ export CXX=/usr/bin/clang++
TOPDIR=$(pwd)

git config --global http.sslverify false

cd 3rdparty
if [ ! -d ravenna-alsa-lkm ]; then
git clone --single-branch --branch aes67-daemon https://github.com/bondagit/ravenna-alsa-lkm.git
fi

if [ ! -d cpp-httplib ]; then
git clone https://github.com/bondagit/cpp-httplib.git
cd cpp-httplib
git checkout 42f9f9107f87ad2ee04be117dbbadd621c449552
cd ..
fi
cd ..
git submodule update --init --recursive

cd daemon
echo "Building aes67-daemon ..."
Expand All @@ -32,6 +20,7 @@ cmake \
-DENABLE_TESTS=ON \
-DWITH_AVAHI=OFF \
-DFAKE_DRIVER=ON \
-DWITH_STREAMER=OFF \
.
make
cd ..
Expand Down
20 changes: 15 additions & 5 deletions daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ option(FAKE_DRIVER "Use fake driver instead of RAVENNA" OFF)
set(CMAKE_CXX_STANDARD 17)

option(WITH_SYSTEMD "Include systemd notify and watchdog support" OFF)
option(WITH_STREAMER "Enable streamer support" ON)

# ravena lkm _should_ be provided by the CLI. Nonetheless, we should be able
# to find it in system dirs too...
Expand All @@ -24,9 +25,6 @@ if (NOT CPP_HTTPLIB_DIR)
find_path( CPP_HTTPLIB_DIR "httplib.h" REQUIRED)
endif()

find_library(ALSA_LIBRARY NAMES asound)
find_library(AAC_LIBRARY NAMES faac)

find_library(AVAHI_LIBRARY-COMMON NAMES avahi-common)
find_library(AVAHI_LIBRARY-CLIENT NAMES avahi-client)
find_path(AVAHI_INCLUDE_DIR avahi-client/publish.h)
Expand All @@ -37,7 +35,13 @@ find_package(Boost COMPONENTS system thread log program_options REQUIRED)
include_directories(aes67-daemon ${RAVENNA_ALSA_LKM_DIR}/common ${RAVENNA_ALSA_LKM_DIR}/driver ${CPP_HTTPLIB_DIR} ${Boost_INCLUDE_DIR})
add_definitions( -DBOOST_LOG_DYN_LINK -DBOOST_LOG_USE_NATIVE_SYSLOG )
add_compile_options( -Wall )
set(SOURCES error_code.cpp json.cpp main.cpp session_manager.cpp http_server.cpp config.cpp interface.cpp log.cpp sap.cpp browser.cpp rtsp_client.cpp mdns_client.cpp mdns_server.cpp rtsp_server.cpp utils.cpp streamer.cpp)
set(SOURCES error_code.cpp json.cpp main.cpp session_manager.cpp http_server.cpp config.cpp interface.cpp log.cpp sap.cpp browser.cpp rtsp_client.cpp mdns_client.cpp mdns_server.cpp rtsp_server.cpp utils.cpp)

if(WITH_STREAMER)
MESSAGE(STATUS "WITH_STREAMER")
add_definitions(-D_USE_STREAMER_)
list(APPEND SOURCES streamer.cpp)
endif()

if(FAKE_DRIVER)
MESSAGE(STATUS "FAKE_DRIVER")
Expand All @@ -52,7 +56,7 @@ if(ENABLE_TESTS)
add_subdirectory(tests)
endif()

target_link_libraries(aes67-daemon ${Boost_LIBRARIES} ${ALSA_LIBRARY} ${AAC_LIBRARY})
target_link_libraries(aes67-daemon ${Boost_LIBRARIES})
if(WITH_AVAHI)
MESSAGE(STATUS "WITH_AVAHI")
add_definitions(-D_USE_AVAHI_)
Expand All @@ -65,3 +69,9 @@ if(WITH_SYSTEMD)
add_definitions(-D_USE_SYSTEMD_)
target_link_libraries(aes67-daemon systemd)
endif()

if(WITH_STREAMER)
find_library(ALSA_LIBRARY NAMES asound)
find_library(AAC_LIBRARY NAMES faac)
target_link_libraries(aes67-daemon ${ALSA_LIBRARY} ${AAC_LIBRARY})
endif()
19 changes: 18 additions & 1 deletion daemon/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

#define BOOST_BIND_GLOBAL_PLACEHOLDERS

#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -72,7 +74,8 @@ std::shared_ptr<Config> Config::parse(const std::string& filename,
config.streamer_file_duration_ = 1;
if (config.streamer_files_num_ < 4 || config.streamer_files_num_ > 16)
config.streamer_files_num_ = 8;
if (config.streamer_player_buffer_files_num_ < 1 || config.streamer_player_buffer_files_num_ > 2)
if (config.streamer_player_buffer_files_num_ < 1 ||
config.streamer_player_buffer_files_num_ > 2)
config.streamer_player_buffer_files_num_ = 1;

boost::system::error_code ec;
Expand Down Expand Up @@ -169,3 +172,17 @@ std::string Config::get_node_id() const {
return custom_node_id_;
}
}

bool Config::get_streamer_enabled() const {
#ifndef _USE_STREAMER_
return false;
#endif
return streamer_enabled_;
}

bool Config::get_mdns_enabled() const {
#ifndef _USE_AVAHI_
return false;
#endif
return mdns_enabled_;
}
4 changes: 2 additions & 2 deletions daemon/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Config {
return streamer_player_buffer_files_num_;
};
uint8_t get_streamer_channels() const { return streamer_channels_; };
bool get_streamer_enabled() const { return streamer_enabled_; };
bool get_streamer_enabled() const;
int get_log_severity() const { return log_severity_; };
uint32_t get_playout_delay() const { return playout_delay_; };
uint32_t get_tic_frame_size_at_1fs() const { return tic_frame_size_at_1fs_; };
Expand Down Expand Up @@ -73,7 +73,7 @@ class Config {
const std::string& get_ip_addr_str() const { return ip_str_; };
bool get_daemon_restart() const { return daemon_restart_; };
bool get_driver_restart() const { return driver_restart_; };
bool get_mdns_enabled() const { return mdns_enabled_; };
bool get_mdns_enabled() const;
int get_interface_idx() const { return interface_idx_; };
const std::string& get_ptp_status_script() const {
return ptp_status_script_;
Expand Down
8 changes: 8 additions & 0 deletions daemon/http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

#define BOOST_BIND_GLOBAL_PLACEHOLDERS

#include <boost/foreach.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
Expand Down Expand Up @@ -323,6 +325,7 @@ bool HttpServer::init() {
});

/* retrieve streamer info and position */
#ifdef _USE_STREAMER_
svr_.Get("/api/streamer/info/([0-9]+)", [this](const Request& req,
Response& res) {
uint32_t id;
Expand Down Expand Up @@ -377,10 +380,12 @@ bool HttpServer::init() {
set_headers(res, "application/json");
res.body = streamer_info_to_json(info);
});
#endif

/* retrieve streamer file */
svr_.Get("/api/streamer/stream/([0-9]+)/([0-9]+)", [this](const Request& req,
Response& res) {
#ifdef _USE_STREAMER_
if (!config_->get_streamer_enabled()) {
set_error(400, "streamer not enabled", res);
return;
Expand Down Expand Up @@ -411,6 +416,9 @@ bool HttpServer::init() {
res.set_header("X-File-Count", std::to_string(fileCount));
res.set_header("X-File-Current-Id", std::to_string(currentFileId));
res.set_header("X-File-Start-Id", std::to_string(startFileId));
#else
set_error(400, "streamer support not compiled-in", res);
#endif
});

svr_.set_logger([](const Request& req, const Response& res) {
Expand Down
9 changes: 9 additions & 0 deletions daemon/http_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,35 @@
#include "browser.hpp"
#include "config.hpp"
#include "session_manager.hpp"

#ifdef _USE_STREAMER_
#include "streamer.hpp"
#endif

class HttpServer {
public:
HttpServer() = delete;
explicit HttpServer(std::shared_ptr<SessionManager> session_manager,
std::shared_ptr<Browser> browser,
#ifdef _USE_STREAMER_
std::shared_ptr<Streamer> streamer,
#endif
std::shared_ptr<Config> config)
: session_manager_(session_manager),
browser_(browser),
#ifdef _USE_STREAMER_
streamer_(streamer),
#endif
config_(config){};
bool init();
bool terminate();

private:
std::shared_ptr<SessionManager> session_manager_;
std::shared_ptr<Browser> browser_;
#ifdef _USE_STREAMER_
std::shared_ptr<Streamer> streamer_;
#endif
std::shared_ptr<Config> config_;
httplib::Server svr_;
std::future<bool> res_;
Expand Down
7 changes: 6 additions & 1 deletion daemon/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

#define BOOST_BIND_GLOBAL_PLACEHOLDERS

#include <boost/foreach.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
Expand Down Expand Up @@ -290,20 +292,23 @@ std::string remote_sources_to_json(const std::list<RemoteSource>& sources) {
return ss.str();
}

#ifdef _USE_STREAMER_
std::string streamer_info_to_json(const StreamerInfo& info) {
std::stringstream ss;
ss << "{"
<< "\n \"status\": " << unsigned(info.status)
<< ",\n \"file_duration\": " << unsigned(info.file_duration)
<< ",\n \"files_num\": " << unsigned(info.files_num)
<< ",\n \"player_buffer_files_num\": " << unsigned(info.player_buffer_files_num)
<< ",\n \"player_buffer_files_num\": "
<< unsigned(info.player_buffer_files_num)
<< ",\n \"start_file_id\": " << unsigned(info.start_file_id)
<< ",\n \"current_file_id\": " << unsigned(info.current_file_id)
<< ",\n \"channels\": " << unsigned(info.channels)
<< ",\n \"format\": \"" << info.format << "\""
<< ",\n \"rate\": " << unsigned(info.rate) << "\n}\n";
return ss.str();
}
#endif

Config json_to_config_(std::istream& js, Config& config) {
try {
Expand Down
5 changes: 5 additions & 0 deletions daemon/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@

#include "browser.hpp"
#include "session_manager.hpp"

#ifdef _USE_STREAMER_
#include "streamer.hpp"
#endif

/* JSON serializers */
std::string config_to_json(const Config& config);
Expand All @@ -39,7 +42,9 @@ std::string streams_to_json(const std::list<StreamSource>& sources,
const std::list<StreamSink>& sinks);
std::string remote_source_to_json(const RemoteSource& source);
std::string remote_sources_to_json(const std::list<RemoteSource>& sources);
#ifdef _USE_STREAMER_
std::string streamer_info_to_json(const StreamerInfo& info);
#endif

/* JSON deserializers */
Config json_to_config(std::istream& jstream, const Config& curCconfig);
Expand Down
11 changes: 10 additions & 1 deletion daemon/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
#include "mdns_server.hpp"
#include "rtsp_server.hpp"
#include "session_manager.hpp"

#ifdef _USE_STREAMER_
#include "streamer.hpp"
#endif

#ifdef _USE_SYSTEMD_
#include <systemd/sd-daemon.h>
Expand All @@ -40,7 +43,7 @@ namespace po = boost::program_options;
namespace postyle = boost::program_options::command_line_style;
namespace logging = boost::log;

static const std::string version("bondagit-2.0.1");
static const std::string version("bondagit-2.0.2");
static std::atomic<bool> terminate = false;

void termination_handler(int signum) {
Expand Down Expand Up @@ -181,6 +184,7 @@ int main(int argc, char* argv[]) {
}

/* start streamer */
#ifdef _USE_STREAMER_
auto streamer = Streamer::create(session_manager, config);
if (config->get_streamer_enabled() &&
(streamer == nullptr || !streamer->init())) {
Expand All @@ -189,6 +193,9 @@ int main(int argc, char* argv[]) {

/* start http server */
HttpServer http_server(session_manager, browser, streamer, config);
#else
HttpServer http_server(session_manager, browser, config);
#endif
if (!http_server.init()) {
throw std::runtime_error(std::string("HttpServer:: init failed"));
}
Expand Down Expand Up @@ -247,11 +254,13 @@ int main(int argc, char* argv[]) {
}

/* stop streamer */
#ifdef _USE_STREAMER_
if (config->get_streamer_enabled()) {
if (!streamer->terminate()) {
throw std::runtime_error(std::string("Streamer:: terminate failed"));
}
}
#endif

/* stop rtsp server */
if (!rtsp_server.terminate()) {
Expand Down
3 changes: 2 additions & 1 deletion daemon/netlink_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
#include <boost/asio.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/bind.hpp>
#include <boost/bind/bind.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <cstdlib>
#include <iostream>

#include "netlink.hpp"

using namespace boost::placeholders;
using boost::asio::deadline_timer;

class NetlinkClient {
Expand Down
3 changes: 2 additions & 1 deletion daemon/sap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

#include <boost/bind.hpp>
#include <boost/bind/bind.hpp>

#include "sap.hpp"

using namespace boost::placeholders;
using namespace boost::asio;
using namespace boost::asio::ip;

Expand Down
Loading

0 comments on commit cb27938

Please sign in to comment.