mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-05-19 03:56:18 -04:00
libvlc support for rtsp authentication with special characters
This commit is contained in:
@@ -104,6 +104,8 @@ void LibvlcUnlockBuffer(void* opaque, void* picture, void *const *planes) {
|
||||
LibvlcCamera::LibvlcCamera(
|
||||
const Monitor *monitor,
|
||||
const std::string &p_path,
|
||||
const std::string &p_user,
|
||||
const std::string &p_pass,
|
||||
const std::string &p_method,
|
||||
const std::string &p_options,
|
||||
int p_width,
|
||||
@@ -131,6 +133,8 @@ LibvlcCamera::LibvlcCamera(
|
||||
p_record_audio
|
||||
),
|
||||
mPath(p_path),
|
||||
mUser(UriEncode(p_user)),
|
||||
mPass(UriEncode(p_pass)),
|
||||
mMethod(p_method),
|
||||
mOptions(p_options)
|
||||
{
|
||||
@@ -214,6 +218,8 @@ int LibvlcCamera::PrimeCapture() {
|
||||
|
||||
opVect = Split(Options(), ",");
|
||||
|
||||
Debug(1, "Method: '%s'", Method().c_str());
|
||||
|
||||
// Set transport method as specified by method field, rtpUni is default
|
||||
if ( Method() == "rtpMulti" )
|
||||
opVect.push_back("--rtsp-mcast");
|
||||
@@ -241,6 +247,17 @@ int LibvlcCamera::PrimeCapture() {
|
||||
}
|
||||
(*libvlc_log_set_f)(mLibvlcInstance, LibvlcCamera::log_callback, nullptr);
|
||||
|
||||
// recreate the path with encoded authentication info
|
||||
if( mUser.length() > 0 ) {
|
||||
std::string mMaskedPath = remove_authentication(mPath);
|
||||
|
||||
std::string protocol = StringToUpper(mPath.substr(0, 4));
|
||||
if ( protocol == "RTSP" ) {
|
||||
// build the actual uri string with encoded parameters (from the user and pass fields)
|
||||
mPath = StringToLower(protocol) + "://" + mUser + ":" + mPass + "@" + mMaskedPath.substr(7, std::string::npos);
|
||||
Debug(1, "Rebuilt URI with encoded parameters: '%s'", mPath.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
mLibvlcMedia = (*libvlc_media_new_location_f)(mLibvlcInstance, mPath.c_str());
|
||||
if ( mLibvlcMedia == nullptr ) {
|
||||
|
||||
@@ -49,6 +49,8 @@ class LibvlcCamera : public Camera {
|
||||
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 mUser;
|
||||
std::string mPass;
|
||||
std::string mMethod;
|
||||
std::string mOptions;
|
||||
StringVector opVect; // mOptArgV will point into opVect so it needs to hang around
|
||||
@@ -62,7 +64,7 @@ protected:
|
||||
libvlc_media_player_t *mLibvlcMediaPlayer;
|
||||
|
||||
public:
|
||||
LibvlcCamera( const Monitor *monitor, 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 Monitor *monitor, const std::string &path, const std::string &user,const std::string &pass, 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; }
|
||||
|
||||
@@ -699,6 +699,8 @@ void Monitor::LoadCamera() {
|
||||
#if HAVE_LIBVLC
|
||||
camera = zm::make_unique<LibvlcCamera>(this,
|
||||
path.c_str(),
|
||||
user,
|
||||
pass,
|
||||
method,
|
||||
options,
|
||||
camera_width,
|
||||
|
||||
Reference in New Issue
Block a user