add zm_terminate to main while loop
This commit is contained in:
parent
4d4a7a4221
commit
8ed015966b
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "zm.h"
|
#include "zm.h"
|
||||||
|
#include "zm_signal.h"
|
||||||
#include "zm_libvlc_camera.h"
|
#include "zm_libvlc_camera.h"
|
||||||
|
|
||||||
#if HAVE_LIBVLC
|
#if HAVE_LIBVLC
|
||||||
|
@ -39,7 +40,7 @@ void LibvlcUnlockBuffer(void* opaque, void* picture, void *const *planes) {
|
||||||
LibvlcPrivateData* data = reinterpret_cast<LibvlcPrivateData*>(opaque);
|
LibvlcPrivateData* data = reinterpret_cast<LibvlcPrivateData*>(opaque);
|
||||||
|
|
||||||
bool newFrame = false;
|
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] ) {
|
if ( data->buffer[i] != data->prevBuffer[i] ) {
|
||||||
newFrame = true;
|
newFrame = true;
|
||||||
break;
|
break;
|
||||||
|
@ -56,8 +57,35 @@ 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 ) :
|
LibvlcCamera::LibvlcCamera(
|
||||||
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 ),
|
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),
|
mPath(p_path),
|
||||||
mMethod(p_method),
|
mMethod(p_method),
|
||||||
mOptions(p_options)
|
mOptions(p_options)
|
||||||
|
@ -118,11 +146,13 @@ void LibvlcCamera::Initialise() {
|
||||||
|
|
||||||
void LibvlcCamera::Terminate() {
|
void LibvlcCamera::Terminate() {
|
||||||
libvlc_media_player_stop(mLibvlcMediaPlayer);
|
libvlc_media_player_stop(mLibvlcMediaPlayer);
|
||||||
if(mLibvlcData.buffer != NULL) {
|
if ( mLibvlcData.buffer ) {
|
||||||
zm_freealigned(mLibvlcData.buffer);
|
zm_freealigned(mLibvlcData.buffer);
|
||||||
|
mLibvlcData.buffer = NULL;
|
||||||
}
|
}
|
||||||
if(mLibvlcData.prevBuffer != NULL) {
|
if ( mLibvlcData.prevBuffer ) {
|
||||||
zm_freealigned(mLibvlcData.prevBuffer);
|
zm_freealigned(mLibvlcData.prevBuffer);
|
||||||
|
mLibvlcData.prevBuffer = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,6 +169,8 @@ int LibvlcCamera::PrimeCapture() {
|
||||||
else if ( Method() == "rtpRtspHttp" )
|
else if ( Method() == "rtpRtspHttp" )
|
||||||
opVect.push_back("--rtsp-http");
|
opVect.push_back("--rtsp-http");
|
||||||
|
|
||||||
|
opVect.push_back("--no-audio");
|
||||||
|
|
||||||
if ( opVect.size() > 0 ) {
|
if ( opVect.size() > 0 ) {
|
||||||
mOptArgV = new char*[opVect.size()];
|
mOptArgV = new char*[opVect.size()];
|
||||||
Debug(2, "Number of Options: %d",opVect.size());
|
Debug(2, "Number of Options: %d",opVect.size());
|
||||||
|
@ -150,16 +182,22 @@ int LibvlcCamera::PrimeCapture() {
|
||||||
}
|
}
|
||||||
|
|
||||||
mLibvlcInstance = libvlc_new(opVect.size(), (const char* const*)mOptArgV);
|
mLibvlcInstance = libvlc_new(opVect.size(), (const char* const*)mOptArgV);
|
||||||
if ( mLibvlcInstance == NULL )
|
if ( mLibvlcInstance == NULL ) {
|
||||||
Fatal("Unable to create libvlc instance due to: %s", libvlc_errmsg());
|
Error("Unable to create libvlc instance due to: %s", libvlc_errmsg());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
mLibvlcMedia = libvlc_media_new_location(mLibvlcInstance, mPath.c_str());
|
mLibvlcMedia = libvlc_media_new_location(mLibvlcInstance, mPath.c_str());
|
||||||
if(mLibvlcMedia == NULL)
|
if ( mLibvlcMedia == NULL ) {
|
||||||
Fatal("Unable to open input %s due to: %s", mPath.c_str(), libvlc_errmsg());
|
Error("Unable to open input %s due to: %s", mPath.c_str(), libvlc_errmsg());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
mLibvlcMediaPlayer = libvlc_media_player_new_from_media(mLibvlcMedia);
|
mLibvlcMediaPlayer = libvlc_media_player_new_from_media(mLibvlcMedia);
|
||||||
if(mLibvlcMediaPlayer == NULL)
|
if ( mLibvlcMediaPlayer == NULL ) {
|
||||||
Fatal("Unable to create player for %s due to: %s", mPath.c_str(), libvlc_errmsg());
|
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_format(mLibvlcMediaPlayer, mTargetChroma.c_str(), width, height, width * mBpp);
|
||||||
libvlc_video_set_callbacks(mLibvlcMediaPlayer, &LibvlcLockBuffer, &LibvlcUnlockBuffer, NULL, &mLibvlcData);
|
libvlc_video_set_callbacks(mLibvlcMediaPlayer, &LibvlcLockBuffer, &LibvlcUnlockBuffer, NULL, &mLibvlcData);
|
||||||
|
@ -177,13 +215,16 @@ int LibvlcCamera::PrimeCapture() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int LibvlcCamera::PreCapture() {
|
int LibvlcCamera::PreCapture() {
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should not return -1 as cancels capture. Always wait for image if available.
|
// Should not return -1 as cancels capture. Always wait for image if available.
|
||||||
int LibvlcCamera::Capture(Image &image) {
|
int LibvlcCamera::Capture(Image &image) {
|
||||||
while(!mLibvlcData.newImage.getValueImmediate())
|
while( !mLibvlcData.newImage.getValueImmediate() ) {
|
||||||
|
if (zm_terminate)
|
||||||
|
return 0;
|
||||||
mLibvlcData.newImage.getUpdatedValue(1);
|
mLibvlcData.newImage.getUpdatedValue(1);
|
||||||
|
}
|
||||||
|
|
||||||
mLibvlcData.mutex.lock();
|
mLibvlcData.mutex.lock();
|
||||||
image.Assign(width, height, colours, subpixelorder, mLibvlcData.buffer, width * height * mBpp);
|
image.Assign(width, height, colours, subpixelorder, mLibvlcData.buffer, width * height * mBpp);
|
||||||
|
@ -193,13 +234,12 @@ int LibvlcCamera::Capture( Image &image ) {
|
||||||
return 1;
|
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) {
|
int LibvlcCamera::CaptureAndRecord(Image &image, timeval recording, char* event_directory) {
|
||||||
return (0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LibvlcCamera::PostCapture() {
|
int LibvlcCamera::PostCapture() {
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HAVE_LIBVLC
|
#endif // HAVE_LIBVLC
|
||||||
|
|
Loading…
Reference in New Issue