From 32cd3ce5ba33d85429365cbe2a43872371351fb9 Mon Sep 17 00:00:00 2001 From: rmens Date: Sat, 30 Aug 2025 14:36:16 +0200 Subject: feat: use etiLog --- src/VLCInput.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/VLCInput.cpp') diff --git a/src/VLCInput.cpp b/src/VLCInput.cpp index ef4cfc4..0006d8d 100644 --- a/src/VLCInput.cpp +++ b/src/VLCInput.cpp @@ -25,6 +25,7 @@ #include #include "VLCInput.h" +#include "Log.h" #include "config.h" @@ -142,20 +143,20 @@ void VLCInput::prepare() throw runtime_error("Cannot start VLC input. Fault detected previously!"); } - fprintf(stderr, "Initialising VLC...\n"); + etiLog.level(info) << "Initialising VLC..."; long long int handleStream_address; long long int prepareRender_address; switch (check_vlc_uses_size_t()) { case vlc_data_type_e::vlc_uses_unsigned_int: - fprintf(stderr, "You are using VLC with unsigned int size callbacks\n"); + etiLog.level(info) << "You are using VLC with unsigned int size callbacks"; handleStream_address = (long long int)(intptr_t)(void*)&handleStream; prepareRender_address = (long long int)(intptr_t)(void*)&prepareRender; break; case vlc_data_type_e::vlc_uses_size_t: - fprintf(stderr, "You are using VLC with size_t size callbacks\n"); + etiLog.level(info) << "You are using VLC with size_t size callbacks"; handleStream_address = (long long int)(intptr_t)(void*)&handleStream_size_t; prepareRender_address = (long long int)(intptr_t)(void*)&prepareRender_size_t; @@ -179,9 +180,9 @@ void VLCInput::prepare() back_inserter(vlc_args)); if (m_verbosity) { - fprintf(stderr, "Initialising VLC with options:\n"); + etiLog.level(info) << "Initialising VLC with options:"; for (const auto& arg : vlc_args) { - fprintf(stderr, " %s\n", arg.c_str()); + etiLog.level(info) << " " << arg; } } @@ -224,7 +225,7 @@ void VLCInput::prepare() (long long int)(intptr_t)this); if (m_verbosity) { - fprintf(stderr, "Setting VLC media option: %s\n", smem_options); + etiLog.level(debug) << "Setting VLC media option: " << smem_options; } libvlc_media_add_option(m, smem_options); @@ -296,14 +297,14 @@ void VLCInput::exit_cb() if (m_running) { std::lock_guard lock(m_queue_mutex); - fprintf(stderr, "VLC exit, restarting...\n"); + etiLog.level(warn) << "VLC exit, restarting..."; cleanup(); m_current_buf.clear(); prepare(); } else { - fprintf(stderr, "VLC exit.\n"); + etiLog.level(info) << "VLC exit."; } } @@ -342,8 +343,7 @@ void VLCInput::postRender_cb(unsigned int channels, size_t size) } } else { - fprintf(stderr, "Got invalid number of channels back from VLC! " - "requested: %d, got %d\n", m_channels, channels); + etiLog.level(error) << "Got invalid number of channels back from VLC! requested: " << m_channels << ", got " << channels; m_running = false; m_fault = true; } @@ -388,7 +388,7 @@ ssize_t VLCInput::m_read(uint8_t* buf, size_t length) libvlc_media_t *media = libvlc_media_player_get_media(m_mp); if (!media) { - fprintf(stderr, "VLC no media\n"); + etiLog.level(error) << "VLC no media"; err = -1; break; } @@ -397,7 +397,7 @@ ssize_t VLCInput::m_read(uint8_t* buf, size_t length) if (!(st == libvlc_Opening || st == libvlc_Buffering || st == libvlc_Playing) ) { - fprintf(stderr, "VLC state is %d\n", st); + etiLog.level(warn) << "VLC state is " << st; err = -1; break; } @@ -505,8 +505,8 @@ vlc_data_type_e check_vlc_uses_size_t() } } - fprintf(stderr, "Error detecting VLC version!\n"); - fprintf(stderr, " you are using %s\n", libvlc_get_version()); + etiLog.level(error) << "Error detecting VLC version!"; + etiLog.level(error) << " you are using " << libvlc_get_version(); throw runtime_error("Cannot identify VLC datatype!"); } -- cgit v1.2.3 From d31dad0b24775cf84d308b94c3fbd0187c476c14 Mon Sep 17 00:00:00 2001 From: rmens Date: Sat, 30 Aug 2025 14:48:17 +0200 Subject: feat: route VLC log through etiLog --- src/VLCInput.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'src/VLCInput.cpp') diff --git a/src/VLCInput.cpp b/src/VLCInput.cpp index 0006d8d..e3e815e 100644 --- a/src/VLCInput.cpp +++ b/src/VLCInput.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "VLCInput.h" #include "Log.h" @@ -123,6 +124,61 @@ void handleVLCExit(void* opaque) ((VLCInput*)opaque)->exit_cb(); } +/*! VLC Log callback to route VLC messages through etiLog */ +void handleVLCLog(void* data, int level, const libvlc_log_t* ctx, const char* fmt, va_list args) +{ + // Map VLC log levels to etiLog levels + log_level_t etiLogLevel; + switch (level) { + case LIBVLC_DEBUG: + etiLogLevel = debug; + break; + case LIBVLC_NOTICE: + etiLogLevel = info; + break; + case LIBVLC_WARNING: + etiLogLevel = warn; + break; + case LIBVLC_ERROR: + etiLogLevel = error; + break; + default: + etiLogLevel = debug; // Default to debug for unknown levels + break; + } + + // Format the message using vsnprintf + char buffer[1024]; + int ret = vsnprintf(buffer, sizeof(buffer), fmt, args); + + if (ret > 0) { + // Get module and object information from context if available + const char* module = nullptr; + const char* file = nullptr; + unsigned line = 0; + const char* object_type = nullptr; + const char* header = nullptr; + uintptr_t object_id = 0; + + libvlc_log_get_context(ctx, &module, &file, &line); + libvlc_log_get_object(ctx, &object_type, &header, &object_id); + + // Use module name if available, otherwise use object type + const char* identifier = nullptr; + if (module && strlen(module) > 0) { + identifier = module; + } else if (object_type && strlen(object_type) > 0) { + identifier = object_type; + } + + if (identifier) { + etiLog.level(etiLogLevel) << "VLC [" << identifier << "] " << buffer; + } else { + etiLog.level(etiLogLevel) << "VLC " << buffer; + } + } +} + VLCInput::~VLCInput() { m_running = false; @@ -198,6 +254,9 @@ void VLCInput::prepare() throw runtime_error("VLC initialisation failed"); } + // Set up VLC log callback to route messages through etiLog + libvlc_log_set(m_vlc, handleVLCLog, this); + libvlc_set_exit_handler(m_vlc, handleVLCExit, this); // Load the media -- cgit v1.2.3