aboutsummaryrefslogtreecommitdiffstats
path: root/src/VLCInput.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/VLCInput.cpp')
-rw-r--r--src/VLCInput.cpp87
1 files changed, 73 insertions, 14 deletions
diff --git a/src/VLCInput.cpp b/src/VLCInput.cpp
index ef4cfc4..e3e815e 100644
--- a/src/VLCInput.cpp
+++ b/src/VLCInput.cpp
@@ -23,8 +23,10 @@
#include <chrono>
#include <algorithm>
#include <functional>
+#include <cstdarg>
#include "VLCInput.h"
+#include "Log.h"
#include "config.h"
@@ -122,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;
@@ -142,20 +199,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 +236,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;
}
}
@@ -197,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
@@ -224,7 +284,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 +356,14 @@ void VLCInput::exit_cb()
if (m_running) {
std::lock_guard<std::mutex> 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 +402,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 +447,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 +456,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 +564,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!");
}