Merge pull request #2401 from connortechnology/vlc_logging

add a logging callback to the libvlc camera
This commit is contained in:
Andrew Bauer 2019-01-08 13:49:51 -06:00 committed by GitHub
commit 9811679cc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 3 deletions

View File

@ -186,6 +186,8 @@ int LibvlcCamera::PrimeCapture() {
Error("Unable to create libvlc instance due to: %s", libvlc_errmsg());
return -1;
}
libvlc_log_set(mLibvlcInstance, LibvlcCamera::log_callback, NULL);
mLibvlcMedia = libvlc_media_new_location(mLibvlcInstance, mPath.c_str());
if ( mLibvlcMedia == NULL ) {
@ -214,6 +216,7 @@ int LibvlcCamera::PrimeCapture() {
return 0;
}
int LibvlcCamera::PreCapture() {
return 0;
}
@ -244,4 +247,28 @@ int LibvlcCamera::PostCapture() {
return 0;
}
void LibvlcCamera::log_callback(void *ptr, int level, const libvlc_log_t *ctx, const char *fmt, va_list vargs) {
Logger *log = Logger::fetch();
int log_level = Logger::NOLOG;
if ( level == LIBVLC_ERROR ) {
log_level = Logger::WARNING; // ffmpeg outputs a lot of errors that don't really affect anything.
//log_level = Logger::ERROR;
} else if ( level == LIBVLC_WARNING ) {
log_level = Logger::INFO;
//log_level = Logger::WARNING;
} else if ( level == LIBVLC_NOTICE ) {
log_level = Logger::DEBUG1;
//log_level = Logger::INFO;
} else if ( level == LIBVLC_DEBUG ) {
log_level = Logger::DEBUG3;
} else {
Error("Unknown log level %d", level);
}
if ( log ) {
char logString[8192];
vsnprintf(logString, sizeof(logString)-1, fmt, vargs);
log->logPrint(false, __FILE__, __LINE__, log_level, logString);
}
}
#endif // HAVE_LIBVLC

View File

@ -42,6 +42,8 @@ struct LibvlcPrivateData
};
class LibvlcCamera : public Camera {
private:
static void log_callback( void *ptr, int level, const libvlc_log_t *ctx, const char *format, va_list vargs );
protected:
std::string mPath;
std::string mMethod;
@ -59,9 +61,9 @@ public:
LibvlcCamera( int p_id, const std::string &path, const std::string &p_method, const std::string &p_options, int p_width, int p_height, int p_colours, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture, bool p_record_audio );
~LibvlcCamera();
const std::string &Path() const { return( mPath ); }
const std::string &Options() const { return( mOptions ); }
const std::string &Method() const { return( mMethod ); }
const std::string &Path() const { return mPath; }
const std::string &Options() const { return mOptions; }
const std::string &Method() const { return mMethod; }
void Initialise();
void Terminate();