diff --git a/src/zm_libvlc_camera.cpp b/src/zm_libvlc_camera.cpp index bc259fd8f..6508dcdf9 100644 --- a/src/zm_libvlc_camera.cpp +++ b/src/zm_libvlc_camera.cpp @@ -18,6 +18,7 @@ */ #include "zm.h" +#include "zm_signal.h" #include "zm_libvlc_camera.h" #if HAVE_LIBVLC @@ -39,7 +40,7 @@ void LibvlcUnlockBuffer(void* opaque, void* picture, void *const *planes) { LibvlcPrivateData* data = reinterpret_cast(opaque); bool newFrame = false; - for( uint32_t i = 0; i < data->bufferSize; i++ ) { + for( unsigned int i=0; i < data->bufferSize; i++ ) { if ( data->buffer[i] != data->prevBuffer[i] ) { newFrame = true; break; @@ -56,11 +57,38 @@ void LibvlcUnlockBuffer(void* opaque, void* picture, void *const *planes) { } } -LibvlcCamera::LibvlcCamera( int p_id, const std::string &p_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 ) : - Camera( p_id, LIBVLC_SRC, p_width, p_height, p_colours, ZM_SUBPIX_ORDER_DEFAULT_FOR_COLOUR(p_colours), p_brightness, p_contrast, p_hue, p_colour, p_capture, p_record_audio ), - mPath( p_path ), - mMethod( p_method ), - mOptions( p_options ) +LibvlcCamera::LibvlcCamera( + int p_id, + const std::string &p_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 + ) : + Camera( + p_id, + LIBVLC_SRC, + p_width, + p_height, + p_colours, + ZM_SUBPIX_ORDER_DEFAULT_FOR_COLOUR(p_colours), + p_brightness, + p_contrast, + p_hue, + p_colour, + p_capture, + p_record_audio + ), + mPath(p_path), + mMethod(p_method), + mOptions(p_options) { mLibvlcInstance = NULL; mLibvlcMedia = NULL; @@ -70,15 +98,15 @@ LibvlcCamera::LibvlcCamera( int p_id, const std::string &p_path, const std::stri mOptArgV = NULL; /* Has to be located inside the constructor so other components such as zma will receive correct colours and subpixel order */ - if(colours == ZM_COLOUR_RGB32) { + if ( colours == ZM_COLOUR_RGB32 ) { subpixelorder = ZM_SUBPIX_ORDER_BGRA; mTargetChroma = "RV32"; mBpp = 4; - } else if(colours == ZM_COLOUR_RGB24) { + } else if ( colours == ZM_COLOUR_RGB24 ) { subpixelorder = ZM_SUBPIX_ORDER_BGR; mTargetChroma = "RV24"; mBpp = 3; - } else if(colours == ZM_COLOUR_GRAY8) { + } else if ( colours == ZM_COLOUR_GRAY8 ) { subpixelorder = ZM_SUBPIX_ORDER_NONE; mTargetChroma = "GREY"; mBpp = 1; @@ -118,11 +146,13 @@ void LibvlcCamera::Initialise() { void LibvlcCamera::Terminate() { libvlc_media_player_stop(mLibvlcMediaPlayer); - if(mLibvlcData.buffer != NULL) { + if ( mLibvlcData.buffer ) { zm_freealigned(mLibvlcData.buffer); + mLibvlcData.buffer = NULL; } - if(mLibvlcData.prevBuffer != NULL) { + if ( mLibvlcData.prevBuffer ) { zm_freealigned(mLibvlcData.prevBuffer); + mLibvlcData.prevBuffer = NULL; } } @@ -139,6 +169,8 @@ int LibvlcCamera::PrimeCapture() { else if ( Method() == "rtpRtspHttp" ) opVect.push_back("--rtsp-http"); + opVect.push_back("--no-audio"); + if ( opVect.size() > 0 ) { mOptArgV = new char*[opVect.size()]; Debug(2, "Number of Options: %d",opVect.size()); @@ -149,17 +181,23 @@ int LibvlcCamera::PrimeCapture() { } } - mLibvlcInstance = libvlc_new (opVect.size(), (const char* const*)mOptArgV); - if ( mLibvlcInstance == NULL ) - Fatal("Unable to create libvlc instance due to: %s", libvlc_errmsg()); + mLibvlcInstance = libvlc_new(opVect.size(), (const char* const*)mOptArgV); + if ( mLibvlcInstance == NULL ) { + Error("Unable to create libvlc instance due to: %s", libvlc_errmsg()); + return -1; + } mLibvlcMedia = libvlc_media_new_location(mLibvlcInstance, mPath.c_str()); - if(mLibvlcMedia == NULL) - Fatal("Unable to open input %s due to: %s", mPath.c_str(), libvlc_errmsg()); + if ( mLibvlcMedia == NULL ) { + Error("Unable to open input %s due to: %s", mPath.c_str(), libvlc_errmsg()); + return -1; + } mLibvlcMediaPlayer = libvlc_media_player_new_from_media(mLibvlcMedia); - if(mLibvlcMediaPlayer == NULL) - Fatal("Unable to create player for %s due to: %s", mPath.c_str(), libvlc_errmsg()); + if ( mLibvlcMediaPlayer == NULL ) { + Error("Unable to create player for %s due to: %s", mPath.c_str(), libvlc_errmsg()); + return -1; + } libvlc_video_set_format(mLibvlcMediaPlayer, mTargetChroma.c_str(), width, height, width * mBpp); libvlc_video_set_callbacks(mLibvlcMediaPlayer, &LibvlcLockBuffer, &LibvlcUnlockBuffer, NULL, &mLibvlcData); @@ -177,13 +215,16 @@ int LibvlcCamera::PrimeCapture() { } int LibvlcCamera::PreCapture() { - return(0); + return 0; } // Should not return -1 as cancels capture. Always wait for image if available. -int LibvlcCamera::Capture( Image &image ) { - while(!mLibvlcData.newImage.getValueImmediate()) +int LibvlcCamera::Capture(Image &image) { + while( !mLibvlcData.newImage.getValueImmediate() ) { + if (zm_terminate) + return 0; mLibvlcData.newImage.getUpdatedValue(1); + } mLibvlcData.mutex.lock(); image.Assign(width, height, colours, subpixelorder, mLibvlcData.buffer, width * height * mBpp); @@ -193,13 +234,12 @@ int LibvlcCamera::Capture( Image &image ) { return 1; } -// Should not return -1 as cancels capture. Always wait for image if available. int LibvlcCamera::CaptureAndRecord(Image &image, timeval recording, char* event_directory) { - return (0); + return 0; } int LibvlcCamera::PostCapture() { - return(0); + return 0; } #endif // HAVE_LIBVLC