Merge ../ZoneMinder.connortechnology
This commit is contained in:
commit
dbeb000505
|
@ -167,11 +167,8 @@ int FfmpegCamera::Capture( Image &image )
|
|||
Debug( 5, "Got packet from stream %d dts (%d) pts(%d)", packet.stream_index, packet.pts, packet.dts );
|
||||
// What about audio stream? Maybe someday we could do sound detection...
|
||||
if ( packet.stream_index == mVideoStreamId ) {
|
||||
#if LIBAVCODEC_VERSION_CHECK(52, 23, 0, 23, 0)
|
||||
if (avcodec_decode_video2(mVideoCodecContext, mRawFrame, &frameComplete, &packet) < 0)
|
||||
#else
|
||||
if (avcodec_decode_video(mVideoCodecContext, mRawFrame, &frameComplete, packet.data, packet.size) < 0)
|
||||
#endif
|
||||
int ret = zm_avcodec_decode_video( mVideoCodecContext, mRawFrame, &frameComplete, &packet );
|
||||
if ( ret < 0 )
|
||||
Fatal( "Unable to decode frame at frame %d", frameCount );
|
||||
|
||||
Debug( 4, "Decoded video packet at frame %d", frameCount );
|
||||
|
@ -639,6 +636,7 @@ int FfmpegCamera::CaptureAndRecord( Image &image, timeval recording, char* event
|
|||
unsigned int packet_count = 0;
|
||||
ZMPacket *queued_packet;
|
||||
|
||||
// Clear all packets that predate the moment when the recording began
|
||||
packetqueue.clear_unwanted_packets( &recording, mVideoStreamId );
|
||||
|
||||
while ( ( queued_packet = packetqueue.popPacket() ) ) {
|
||||
|
@ -673,7 +671,7 @@ int FfmpegCamera::CaptureAndRecord( Image &image, timeval recording, char* event
|
|||
|
||||
// Buffer video packets, since we are not recording.
|
||||
// All audio packets are keyframes, so only if it's a video keyframe
|
||||
if ( packet.stream_index == mVideoStreamId) {
|
||||
if ( packet.stream_index == mVideoStreamId ) {
|
||||
if ( key_frame ) {
|
||||
Debug(3, "Clearing queue");
|
||||
packetqueue.clearQueue( monitor->GetPreEventCount(), mVideoStreamId );
|
||||
|
@ -688,18 +686,19 @@ else if ( packet.pts && video_last_pts > packet.pts ) {
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (
|
||||
( packet.stream_index != mAudioStreamId || record_audio )
|
||||
&&
|
||||
( key_frame || packetqueue.size() )
|
||||
) {
|
||||
packetqueue.queuePacket( &packet );
|
||||
|
||||
// The following lines should ensure that the queue always begins with a video keyframe
|
||||
if ( packet.stream_index == mAudioStreamId ) {
|
||||
if ( record_audio && packetqueue.size() ) // if it's audio, and we are doing audio, and there is already something in the queue
|
||||
packetqueue.queuePacket( &packet );
|
||||
} else if ( packet.stream_index == mVideoStreamId ) {
|
||||
if ( key_frame || packetqueue.size() ) // it's a keyframe or we already have something in the queue
|
||||
packetqueue.queuePacket( &packet );
|
||||
}
|
||||
} // end if recording or not
|
||||
|
||||
if ( packet.stream_index == mVideoStreamId ) {
|
||||
if ( videoStore ) {
|
||||
if ( videoStore ) {
|
||||
//Write the packet to our video store
|
||||
int ret = videoStore->writeVideoFramePacket( &packet );
|
||||
if ( ret < 0 ) { //Less than zero and we skipped a frame
|
||||
|
|
|
@ -60,14 +60,12 @@ ZMPacket* zm_packetqueue::popPacket( ) {
|
|||
|
||||
unsigned int zm_packetqueue::clearQueue( unsigned int frames_to_keep, int stream_id ) {
|
||||
|
||||
Debug(3, "Clearing all but %d frames", frames_to_keep );
|
||||
Debug(3, "Clearing all but %d frames, queue has %d", frames_to_keep, pktQueue.size() );
|
||||
frames_to_keep += 1;
|
||||
|
||||
if ( pktQueue.empty() ) {
|
||||
Debug(3, "Queue is empty");
|
||||
return 0;
|
||||
} else {
|
||||
Debug(3, "Queue has (%d)", pktQueue.size() );
|
||||
}
|
||||
|
||||
list<ZMPacket *>::reverse_iterator it;
|
||||
|
@ -77,18 +75,19 @@ unsigned int zm_packetqueue::clearQueue( unsigned int frames_to_keep, int stream
|
|||
ZMPacket *zm_packet = *it;
|
||||
AVPacket *av_packet = &(zm_packet->packet);
|
||||
|
||||
Debug(3, "Looking at packet with stream index (%d) with keyframe (%d), frames_to_keep is (%d)", av_packet->stream_index, ( av_packet->flags & AV_PKT_FLAG_KEY ), frames_to_keep );
|
||||
Debug(4, "Looking at packet with stream index (%d) with keyframe (%d), frames_to_keep is (%d)", av_packet->stream_index, ( av_packet->flags & AV_PKT_FLAG_KEY ), frames_to_keep );
|
||||
|
||||
// Want frames_to_keep video keyframes. Otherwise, we may not have enough
|
||||
if ( ( av_packet->stream_index == stream_id) && ( av_packet->flags & AV_PKT_FLAG_KEY ) ) {
|
||||
if (!frames_to_keep)
|
||||
break;
|
||||
frames_to_keep --;
|
||||
}
|
||||
}
|
||||
if ( frames_to_keep ) {
|
||||
Debug(3, "Hit end of queue, still need (%d) video keyframes", frames_to_keep );
|
||||
}
|
||||
unsigned int delete_count = 0;
|
||||
while ( it != pktQueue.rend() ) {
|
||||
Debug(3, "Deleting a packet from the front, count is (%d)", delete_count );
|
||||
Debug(4, "Deleting a packet from the front, count is (%d)", delete_count );
|
||||
|
||||
packet = pktQueue.front();
|
||||
pktQueue.pop_front();
|
||||
|
@ -96,6 +95,7 @@ unsigned int zm_packetqueue::clearQueue( unsigned int frames_to_keep, int stream
|
|||
|
||||
delete_count += 1;
|
||||
}
|
||||
Debug(3, "Deleted (%d) packets", delete_count );
|
||||
return delete_count;
|
||||
} // end unsigned int zm_packetqueue::clearQueue( unsigned int frames_to_keep, int stream_id )
|
||||
|
||||
|
@ -123,10 +123,10 @@ void zm_packetqueue::clear_unwanted_packets( timeval *recording_started, int mVi
|
|||
// Step 2 - pop packets until we get to the packet in step 2
|
||||
list<ZMPacket *>::reverse_iterator it;
|
||||
|
||||
Debug(3, "Looking for keyframe after start recording stream id (%d)", mVideoStreamId );
|
||||
for ( it = pktQueue.rbegin(); it != pktQueue.rend(); ++ it ) {
|
||||
ZMPacket *zm_packet = *it;
|
||||
AVPacket *av_packet = &(zm_packet->packet);
|
||||
Debug(1, "Looking for keyframe after start" );
|
||||
if (
|
||||
( av_packet->flags & AV_PKT_FLAG_KEY )
|
||||
&&
|
||||
|
@ -134,7 +134,7 @@ Debug(1, "Looking for keyframe after start" );
|
|||
&&
|
||||
timercmp( &(zm_packet->timestamp), recording_started, < )
|
||||
) {
|
||||
Debug(1, "Found keyframe before start" );
|
||||
Debug(3, "Found keyframe before start with stream index (%d) with keyframe (%d)", av_packet->stream_index, ( av_packet->flags & AV_PKT_FLAG_KEY ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -143,10 +143,29 @@ Debug(1, "Found keyframe before start" );
|
|||
return;
|
||||
}
|
||||
|
||||
ZMPacket *zm_packet = *it;
|
||||
AVPacket *av_packet = &(zm_packet->packet);
|
||||
Debug(3, "Found packet before start with stream index (%d) with keyframe (%d), distance(%d), size(%d)",
|
||||
av_packet->stream_index,
|
||||
( av_packet->flags & AV_PKT_FLAG_KEY ),
|
||||
distance( it, pktQueue.rend() ),
|
||||
pktQueue.size() );
|
||||
|
||||
unsigned int deleted_frames = 0;
|
||||
ZMPacket *packet = NULL;
|
||||
while ( pktQueue.rend() != it ) {
|
||||
while ( distance( it, pktQueue.rend() ) > 1 ) {
|
||||
//while ( pktQueue.rend() != it ) {
|
||||
packet = pktQueue.front();
|
||||
pktQueue.pop_front();
|
||||
delete packet;
|
||||
deleted_frames += 1;
|
||||
}
|
||||
|
||||
zm_packet = pktQueue.front();
|
||||
av_packet = &(zm_packet->packet);
|
||||
if ( ( ! ( av_packet->flags & AV_PKT_FLAG_KEY ) ) || ( av_packet->stream_index != mVideoStreamId ) ) {
|
||||
Error( "Done looking for keyframe. Deleted %d frames. Remaining frames in queue: %d stream of head packet is (%d), keyframe (%d), distance(%d), packets(%d)", deleted_frames, pktQueue.size(), av_packet->stream_index, ( av_packet->flags & AV_PKT_FLAG_KEY ), distance( it, pktQueue.rend() ), pktQueue.size() );
|
||||
} else {
|
||||
Debug(1, "Done looking for keyframe. Deleted %d frames. Remaining frames in queue: %d stream of head packet is (%d), keyframe (%d), distance(%d), packets(%d)", deleted_frames, pktQueue.size(), av_packet->stream_index, ( av_packet->flags & AV_PKT_FLAG_KEY ), distance( it, pktQueue.rend() ), pktQueue.size() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,28 +82,36 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in,
|
|||
if (dsr < 0) Warning("%s:%d: title set failed", __FILE__, __LINE__ );
|
||||
|
||||
oc->metadata = pmetadata;
|
||||
|
||||
output_format = oc->oformat;
|
||||
Debug(2, "setting parameters");
|
||||
|
||||
#if LIBAVCODEC_VERSION_CHECK(58, 0, 0, 0, 0)
|
||||
AVCodec *codec = avcodec_find_decoder( video_input_stream->codecpar->codec_id );
|
||||
video_output_context = avcodec_alloc_context3( codec );
|
||||
ret = avcodec_parameters_to_context( video_output_context, video_input_stream->codecpar );
|
||||
if ( ret < 0 ) {
|
||||
Error( "Could not initialize stream parameteres");
|
||||
return;
|
||||
} else {
|
||||
Debug(2, "Success setting parameters");
|
||||
}
|
||||
if ( avcodec_open2( video_output_context, codec, NULL ) < 0 ) {
|
||||
Fatal("Unable to open video out codec\n");
|
||||
}
|
||||
video_output_stream = avformat_new_stream( oc, codec );
|
||||
if (!video_output_stream) {
|
||||
Fatal("Unable to create video out stream\n");
|
||||
} else {
|
||||
Debug(2, "Success creating video out stream" );
|
||||
}
|
||||
#else
|
||||
video_output_stream = avformat_new_stream(oc, (AVCodec*)video_input_context->codec);
|
||||
if (!video_output_stream) {
|
||||
Fatal("Unable to create video out stream\n");
|
||||
} else {
|
||||
Debug(2, "Success creating video out stream" );
|
||||
}
|
||||
|
||||
video_output_context = video_output_stream->codec;
|
||||
|
||||
#if LIBAVCODEC_VERSION_CHECK(58, 0, 0, 0, 0)
|
||||
Debug(2, "setting parameters");
|
||||
ret = avcodec_parameters_to_context( video_output_context, video_input_stream->codecpar );
|
||||
if ( ret < 0 ) {
|
||||
Error( "Could not initialize stream parameteres");
|
||||
return;
|
||||
} else {
|
||||
Debug(2, "Success getting parameters");
|
||||
}
|
||||
#else
|
||||
ret = avcodec_copy_context(video_output_context, video_input_context );
|
||||
if (ret < 0) {
|
||||
Fatal("Unable to copy input video context to output video context %s\n",
|
||||
|
@ -145,6 +153,7 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in,
|
|||
}
|
||||
|
||||
Monitor::Orientation orientation = monitor->getOrientation();
|
||||
Debug(3, "Have orientation" );
|
||||
if ( orientation ) {
|
||||
if ( orientation == Monitor::ROTATE_0 ) {
|
||||
|
||||
|
@ -170,6 +179,7 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in,
|
|||
#endif
|
||||
|
||||
if (audio_input_stream) {
|
||||
Debug(3, "Have audio stream" );
|
||||
audio_input_context = audio_input_stream->codec;
|
||||
|
||||
if ( audio_input_context->codec_id != AV_CODEC_ID_AAC ) {
|
||||
|
@ -187,9 +197,13 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in,
|
|||
Error("Unable to create audio out stream\n");
|
||||
audio_output_stream = NULL;
|
||||
} else {
|
||||
Debug(2, "setting parameters");
|
||||
audio_output_context = audio_output_stream->codec;
|
||||
|
||||
#if LIBAVCODEC_VERSION_CHECK(57, 0, 0, 0, 0)
|
||||
ret = avcodec_parameters_to_context( audio_output_context, audio_input_stream->codecpar );
|
||||
#else
|
||||
ret = avcodec_copy_context(audio_output_context, audio_input_context);
|
||||
#endif
|
||||
if (ret < 0) {
|
||||
Error("Unable to copy audio context %s\n", av_make_error_string(ret).c_str());
|
||||
audio_output_stream = NULL;
|
||||
|
@ -233,7 +247,8 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in,
|
|||
//av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0);
|
||||
//av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0);
|
||||
//av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov+default_base_moof", 0);
|
||||
if ((ret = avformat_write_header(oc, &opts)) < 0) {
|
||||
if ((ret = avformat_write_header(oc, NULL)) < 0) {
|
||||
//if ((ret = avformat_write_header(oc, &opts)) < 0) {
|
||||
Warning("Unable to set movflags to frag_custom+dash+delay_moov");
|
||||
/* Write the stream header, if any. */
|
||||
ret = avformat_write_header(oc, NULL);
|
||||
|
@ -262,14 +277,14 @@ VideoStore::~VideoStore(){
|
|||
if ( audio_output_codec ) {
|
||||
// Do we need to flush the outputs? I have no idea.
|
||||
AVPacket pkt;
|
||||
int got_packet;
|
||||
int got_packet = 0;
|
||||
av_init_packet(&pkt);
|
||||
pkt.data = NULL;
|
||||
pkt.size = 0;
|
||||
int64_t size;
|
||||
|
||||
while(1) {
|
||||
#if LIBAVCODEC_VERSION_CHECK(58, 0, 0, 0, 0)
|
||||
#if LIBAVCODEC_VERSION_CHECK(57, 0, 0, 0, 0)
|
||||
ret = avcodec_receive_packet( audio_output_context, &pkt );
|
||||
#else
|
||||
ret = avcodec_encode_audio2( audio_output_context, &pkt, NULL, &got_packet );
|
||||
|
@ -677,7 +692,7 @@ int VideoStore::writeAudioFramePacket( AVPacket *ipkt ) {
|
|||
if ( audio_output_codec ) {
|
||||
#ifdef HAVE_LIBAVRESAMPLE
|
||||
|
||||
#if 0
|
||||
#if LIBAVCODEC_VERSION_CHECK(57, 0, 0, 0, 0)
|
||||
ret = avcodec_send_packet( audio_input_context, ipkt );
|
||||
if ( ret < 0 ) {
|
||||
Error("avcodec_send_packet fail %s", av_make_error_string(ret).c_str());
|
||||
|
@ -696,26 +711,7 @@ int VideoStore::writeAudioFramePacket( AVPacket *ipkt ) {
|
|||
input_frame->channel_layout,
|
||||
audio_output_context->refcounted_frames
|
||||
);
|
||||
|
||||
ret = avcodec_send_frame( audio_output_context, input_frame );
|
||||
if ( ret < 0 ) {
|
||||
av_frame_unref( input_frame );
|
||||
Error("avcodec_send_frame fail(%d), %s codec is open(%d) is_encoder(%d)", ret, av_make_error_string(ret).c_str(),
|
||||
avcodec_is_open( audio_output_context ),
|
||||
av_codec_is_encoder( audio_output_context->codec)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
ret = avcodec_receive_packet( audio_output_context, &opkt );
|
||||
if ( ret < 0 ) {
|
||||
av_frame_unref( input_frame );
|
||||
Error("avcodec_receive_packet fail %s", av_make_error_string(ret).c_str());
|
||||
return 0;
|
||||
}
|
||||
av_frame_unref( input_frame );
|
||||
#else
|
||||
|
||||
|
||||
/**
|
||||
* Decode the audio frame stored in the packet.
|
||||
* The input audio stream decoder is used to do this.
|
||||
|
@ -736,7 +732,7 @@ int VideoStore::writeAudioFramePacket( AVPacket *ipkt ) {
|
|||
zm_av_packet_unref(&opkt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
int frame_size = input_frame->nb_samples;
|
||||
Debug(4, "Frame size: %d", frame_size );
|
||||
|
||||
|
@ -778,7 +774,7 @@ int VideoStore::writeAudioFramePacket( AVPacket *ipkt ) {
|
|||
* Encode the audio frame and store it in the temporary packet.
|
||||
* The output audio stream encoder is used to do this.
|
||||
*/
|
||||
#if LIBAVCODEC_VERSION_CHECK(58, 0, 0, 0, 0)
|
||||
#if LIBAVCODEC_VERSION_CHECK(57, 0, 0, 0, 0)
|
||||
if (( ret = avcodec_receive_packet( audio_output_context, &opkt )) < 0 ) {
|
||||
#else
|
||||
if (( ret = avcodec_encode_audio2( audio_output_context, &opkt, output_frame, &data_present )) < 0) {
|
||||
|
@ -794,7 +790,6 @@ int VideoStore::writeAudioFramePacket( AVPacket *ipkt ) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
} else {
|
||||
av_init_packet(&opkt);
|
||||
|
|
249
src/zmu.cpp
249
src/zmu.cpp
|
@ -95,8 +95,7 @@ Options for use with monitors:
|
|||
#include "zm_monitor.h"
|
||||
#include "zm_local_camera.h"
|
||||
|
||||
void Usage( int status=-1 )
|
||||
{
|
||||
void Usage( int status=-1 ) {
|
||||
fprintf( stderr, "zmu <-d device_path> [-v] [function] [-U<username> -P<password>]\n" );
|
||||
fprintf( stderr, "zmu <-m monitor_id> [-v] [function] [-U<username> -P<password>]\n" );
|
||||
fprintf( stderr, "General options:\n" );
|
||||
|
@ -167,48 +166,38 @@ typedef enum {
|
|||
ZMU_LIST = 0x10000000,
|
||||
} Function;
|
||||
|
||||
bool ValidateAccess( User *user, int mon_id, int function )
|
||||
{
|
||||
bool ValidateAccess( User *user, int mon_id, int function ) {
|
||||
bool allowed = true;
|
||||
if ( function & (ZMU_STATE|ZMU_IMAGE|ZMU_TIME|ZMU_READ_IDX|ZMU_WRITE_IDX|ZMU_FPS) )
|
||||
{
|
||||
if ( function & (ZMU_STATE|ZMU_IMAGE|ZMU_TIME|ZMU_READ_IDX|ZMU_WRITE_IDX|ZMU_FPS) ) {
|
||||
if ( user->getStream() < User::PERM_VIEW )
|
||||
allowed = false;
|
||||
}
|
||||
if ( function & ZMU_EVENT )
|
||||
{
|
||||
if ( function & ZMU_EVENT ) {
|
||||
if ( user->getEvents() < User::PERM_VIEW )
|
||||
allowed = false;
|
||||
}
|
||||
if ( function & (ZMU_ZONES|ZMU_QUERY|ZMU_LIST) )
|
||||
{
|
||||
if ( function & (ZMU_ZONES|ZMU_QUERY|ZMU_LIST) ) {
|
||||
if ( user->getMonitors() < User::PERM_VIEW )
|
||||
allowed = false;
|
||||
}
|
||||
if ( function & (ZMU_ALARM|ZMU_NOALARM|ZMU_CANCEL|ZMU_RELOAD|ZMU_ENABLE|ZMU_DISABLE|ZMU_SUSPEND|ZMU_RESUME|ZMU_BRIGHTNESS|ZMU_CONTRAST|ZMU_HUE|ZMU_COLOUR) )
|
||||
{
|
||||
if ( function & (ZMU_ALARM|ZMU_NOALARM|ZMU_CANCEL|ZMU_RELOAD|ZMU_ENABLE|ZMU_DISABLE|ZMU_SUSPEND|ZMU_RESUME|ZMU_BRIGHTNESS|ZMU_CONTRAST|ZMU_HUE|ZMU_COLOUR) ) {
|
||||
if ( user->getMonitors() < User::PERM_EDIT )
|
||||
allowed = false;
|
||||
}
|
||||
if ( mon_id > 0 )
|
||||
{
|
||||
if ( !user->canAccess( mon_id ) )
|
||||
{
|
||||
if ( mon_id > 0 ) {
|
||||
if ( !user->canAccess( mon_id ) ) {
|
||||
allowed = false;
|
||||
}
|
||||
}
|
||||
if ( !allowed )
|
||||
{
|
||||
if ( !allowed ) {
|
||||
fprintf( stderr, "Error, insufficient privileges for requested action\n" );
|
||||
exit( -1 );
|
||||
}
|
||||
return( allowed );
|
||||
}
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
if ( access(ZM_CONFIG, R_OK) != 0 )
|
||||
{
|
||||
int main( int argc, char *argv[] ) {
|
||||
if ( access(ZM_CONFIG, R_OK) != 0 ) {
|
||||
fprintf( stderr, "Can't open %s: %s\n", ZM_CONFIG, strerror(errno) );
|
||||
exit( -1 );
|
||||
}
|
||||
|
@ -274,18 +263,15 @@ int main( int argc, char *argv[] )
|
|||
int v4lVersion = 1;
|
||||
#endif // ZM_HAS_V4L2/1
|
||||
#endif // ZM_HAS_V4L
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
int option_index = 0;
|
||||
|
||||
int c = getopt_long (argc, argv, "d:m:vsEDLurwei::S:t::fz::ancqhlB::C::H::O::U:P:A:V:", long_options, &option_index);
|
||||
if (c == -1)
|
||||
{
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c)
|
||||
{
|
||||
switch (c) {
|
||||
case 'd':
|
||||
if ( optarg )
|
||||
device = optarg;
|
||||
|
@ -405,8 +391,7 @@ int main( int argc, char *argv[] )
|
|||
}
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
{
|
||||
if (optind < argc) {
|
||||
fprintf( stderr, "Extraneous options, " );
|
||||
while (optind < argc)
|
||||
fprintf( stderr, "%s ", argv[optind++]);
|
||||
|
@ -414,13 +399,11 @@ int main( int argc, char *argv[] )
|
|||
Usage();
|
||||
}
|
||||
|
||||
if ( device && !(function&ZMU_QUERY) )
|
||||
{
|
||||
if ( device && !(function&ZMU_QUERY) ) {
|
||||
fprintf( stderr, "Error, -d option cannot be used with this option\n" );
|
||||
Usage();
|
||||
}
|
||||
if ( scale != -1 && !(function&ZMU_IMAGE) )
|
||||
{
|
||||
if ( scale != -1 && !(function&ZMU_IMAGE) ) {
|
||||
fprintf( stderr, "Error, -S option cannot be used with this option\n" );
|
||||
Usage();
|
||||
}
|
||||
|
@ -435,46 +418,36 @@ int main( int argc, char *argv[] )
|
|||
|
||||
User *user = 0;
|
||||
|
||||
if ( config.opt_use_auth )
|
||||
{
|
||||
if ( strcmp( config.auth_relay, "none" ) == 0 )
|
||||
{
|
||||
if ( !username )
|
||||
{
|
||||
if ( config.opt_use_auth ) {
|
||||
if ( strcmp( config.auth_relay, "none" ) == 0 ) {
|
||||
if ( !username ) {
|
||||
fprintf( stderr, "Error, username must be supplied\n" );
|
||||
exit( -1 );
|
||||
}
|
||||
|
||||
if ( username )
|
||||
{
|
||||
if ( username ) {
|
||||
user = zmLoadUser( username );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !(username && password) && !auth )
|
||||
{
|
||||
} else {
|
||||
if ( !(username && password) && !auth ) {
|
||||
fprintf( stderr, "Error, username and password or auth string must be supplied\n" );
|
||||
exit( -1 );
|
||||
}
|
||||
|
||||
//if ( strcmp( config.auth_relay, "hashed" ) == 0 )
|
||||
{
|
||||
if ( auth )
|
||||
{
|
||||
if ( auth ) {
|
||||
user = zmLoadAuthUser( auth, false );
|
||||
}
|
||||
}
|
||||
//else if ( strcmp( config.auth_relay, "plain" ) == 0 )
|
||||
{
|
||||
if ( username && password )
|
||||
{
|
||||
if ( username && password ) {
|
||||
user = zmLoadUser( username, password );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !user )
|
||||
{
|
||||
if ( !user ) {
|
||||
fprintf( stderr, "Error, unable to authenticate user\n" );
|
||||
exit( -1 );
|
||||
}
|
||||
|
@ -482,13 +455,10 @@ int main( int argc, char *argv[] )
|
|||
}
|
||||
|
||||
|
||||
if ( mon_id > 0 )
|
||||
{
|
||||
if ( mon_id > 0 ) {
|
||||
Monitor *monitor = Monitor::Load( mon_id, function&(ZMU_QUERY|ZMU_ZONES), Monitor::QUERY );
|
||||
if ( monitor )
|
||||
{
|
||||
if ( verbose )
|
||||
{
|
||||
if ( monitor ) {
|
||||
if ( verbose ) {
|
||||
printf( "Monitor %d(%s)\n", monitor->Id(), monitor->Name() );
|
||||
}
|
||||
if ( ! monitor->connect() ) {
|
||||
|
@ -498,23 +468,19 @@ int main( int argc, char *argv[] )
|
|||
|
||||
char separator = ' ';
|
||||
bool have_output = false;
|
||||
if ( function & ZMU_STATE )
|
||||
{
|
||||
if ( function & ZMU_STATE ) {
|
||||
Monitor::State state = monitor->GetState();
|
||||
if ( verbose )
|
||||
printf( "Current state: %s\n", state==Monitor::ALARM?"Alarm":(state==Monitor::ALERT?"Alert":"Idle") );
|
||||
else
|
||||
{
|
||||
else {
|
||||
if ( have_output ) printf( "%c", separator );
|
||||
printf( "%d", state );
|
||||
have_output = true;
|
||||
}
|
||||
}
|
||||
if ( function & ZMU_TIME )
|
||||
{
|
||||
if ( function & ZMU_TIME ) {
|
||||
struct timeval timestamp = monitor->GetTimestamp( image_idx );
|
||||
if ( verbose )
|
||||
{
|
||||
if ( verbose ) {
|
||||
char timestamp_str[64] = "None";
|
||||
if ( timestamp.tv_sec )
|
||||
strftime( timestamp_str, sizeof(timestamp_str), "%Y-%m-%d %H:%M:%S", localtime( ×tamp.tv_sec ) );
|
||||
|
@ -522,62 +488,50 @@ int main( int argc, char *argv[] )
|
|||
printf( "Time of last image capture: %s.%02ld\n", timestamp_str, timestamp.tv_usec/10000 );
|
||||
else
|
||||
printf( "Time of image %d capture: %s.%02ld\n", image_idx, timestamp_str, timestamp.tv_usec/10000 );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ( have_output ) printf( "%c", separator );
|
||||
printf( "%ld.%02ld", timestamp.tv_sec, timestamp.tv_usec/10000 );
|
||||
have_output = true;
|
||||
}
|
||||
}
|
||||
if ( function & ZMU_READ_IDX )
|
||||
{
|
||||
if ( function & ZMU_READ_IDX ) {
|
||||
if ( verbose )
|
||||
printf( "Last read index: %d\n", monitor->GetLastReadIndex() );
|
||||
else
|
||||
{
|
||||
else {
|
||||
if ( have_output ) printf( "%c", separator );
|
||||
printf( "%d", monitor->GetLastReadIndex() );
|
||||
have_output = true;
|
||||
}
|
||||
}
|
||||
if ( function & ZMU_WRITE_IDX )
|
||||
{
|
||||
if ( function & ZMU_WRITE_IDX ) {
|
||||
if ( verbose )
|
||||
printf( "Last write index: %d\n", monitor->GetLastWriteIndex() );
|
||||
else
|
||||
{
|
||||
else {
|
||||
if ( have_output ) printf( "%c", separator );
|
||||
printf( "%d", monitor->GetLastWriteIndex() );
|
||||
have_output = true;
|
||||
}
|
||||
}
|
||||
if ( function & ZMU_EVENT )
|
||||
{
|
||||
if ( function & ZMU_EVENT ) {
|
||||
if ( verbose )
|
||||
printf( "Last event id: %d\n", monitor->GetLastEvent() );
|
||||
else
|
||||
{
|
||||
else {
|
||||
if ( have_output ) printf( "%c", separator );
|
||||
printf( "%d", monitor->GetLastEvent() );
|
||||
have_output = true;
|
||||
}
|
||||
}
|
||||
if ( function & ZMU_FPS )
|
||||
{
|
||||
if ( function & ZMU_FPS ) {
|
||||
if ( verbose )
|
||||
printf( "Current capture rate: %.2f frames per second\n", monitor->GetFPS() );
|
||||
else
|
||||
{
|
||||
else {
|
||||
if ( have_output ) printf( "%c", separator );
|
||||
printf( "%.2f", monitor->GetFPS() );
|
||||
have_output = true;
|
||||
}
|
||||
}
|
||||
if ( function & ZMU_IMAGE )
|
||||
{
|
||||
if ( verbose )
|
||||
{
|
||||
if ( function & ZMU_IMAGE ) {
|
||||
if ( verbose ) {
|
||||
if ( image_idx == -1 )
|
||||
printf( "Dumping last image captured to Monitor%d.jpg", monitor->Id() );
|
||||
else
|
||||
|
@ -588,77 +542,63 @@ int main( int argc, char *argv[] )
|
|||
}
|
||||
monitor->GetImage( image_idx, scale>0?scale:100 );
|
||||
}
|
||||
if ( function & ZMU_ZONES )
|
||||
{
|
||||
if ( function & ZMU_ZONES ) {
|
||||
if ( verbose )
|
||||
printf( "Dumping zone image to Zones%d.jpg\n", monitor->Id() );
|
||||
monitor->DumpZoneImage( zoneString );
|
||||
}
|
||||
if ( function & ZMU_ALARM )
|
||||
{
|
||||
if ( function & ZMU_ALARM ) {
|
||||
if ( verbose )
|
||||
printf( "Forcing alarm on\n" );
|
||||
monitor->ForceAlarmOn( config.forced_alarm_score, "Forced Web" );
|
||||
}
|
||||
if ( function & ZMU_NOALARM )
|
||||
{
|
||||
if ( function & ZMU_NOALARM ) {
|
||||
if ( verbose )
|
||||
printf( "Forcing alarm off\n" );
|
||||
monitor->ForceAlarmOff();
|
||||
}
|
||||
if ( function & ZMU_CANCEL )
|
||||
{
|
||||
if ( function & ZMU_CANCEL ) {
|
||||
if ( verbose )
|
||||
printf( "Cancelling forced alarm on/off\n" );
|
||||
monitor->CancelForced();
|
||||
}
|
||||
if ( function & ZMU_RELOAD )
|
||||
{
|
||||
if ( function & ZMU_RELOAD ) {
|
||||
if ( verbose )
|
||||
printf( "Reloading monitor settings\n" );
|
||||
monitor->actionReload();
|
||||
}
|
||||
if ( function & ZMU_ENABLE )
|
||||
{
|
||||
if ( function & ZMU_ENABLE ) {
|
||||
if ( verbose )
|
||||
printf( "Enabling event generation\n" );
|
||||
monitor->actionEnable();
|
||||
}
|
||||
if ( function & ZMU_DISABLE )
|
||||
{
|
||||
if ( function & ZMU_DISABLE ) {
|
||||
if ( verbose )
|
||||
printf( "Disabling event generation\n" );
|
||||
monitor->actionDisable();
|
||||
}
|
||||
if ( function & ZMU_SUSPEND )
|
||||
{
|
||||
if ( function & ZMU_SUSPEND ) {
|
||||
if ( verbose )
|
||||
printf( "Suspending event generation\n" );
|
||||
monitor->actionSuspend();
|
||||
}
|
||||
if ( function & ZMU_RESUME )
|
||||
{
|
||||
if ( function & ZMU_RESUME ) {
|
||||
if ( verbose )
|
||||
printf( "Resuming event generation\n" );
|
||||
monitor->actionResume();
|
||||
}
|
||||
if ( function & ZMU_QUERY )
|
||||
{
|
||||
if ( function & ZMU_QUERY ) {
|
||||
char monString[16382] = "";
|
||||
monitor->DumpSettings( monString, verbose );
|
||||
printf( "%s\n", monString );
|
||||
}
|
||||
if ( function & ZMU_BRIGHTNESS )
|
||||
{
|
||||
if ( verbose )
|
||||
{
|
||||
if ( function & ZMU_BRIGHTNESS ) {
|
||||
if ( verbose ) {
|
||||
if ( brightness >= 0 )
|
||||
printf( "New brightness: %d\n", monitor->actionBrightness( brightness ) );
|
||||
else
|
||||
printf( "Current brightness: %d\n", monitor->actionBrightness() );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ( have_output ) printf( "%c", separator );
|
||||
if ( brightness >= 0 )
|
||||
printf( "%d", monitor->actionBrightness( brightness ) );
|
||||
|
@ -667,17 +607,13 @@ int main( int argc, char *argv[] )
|
|||
have_output = true;
|
||||
}
|
||||
}
|
||||
if ( function & ZMU_CONTRAST )
|
||||
{
|
||||
if ( verbose )
|
||||
{
|
||||
if ( function & ZMU_CONTRAST ) {
|
||||
if ( verbose ) {
|
||||
if ( contrast >= 0 )
|
||||
printf( "New brightness: %d\n", monitor->actionContrast( contrast ) );
|
||||
else
|
||||
printf( "Current contrast: %d\n", monitor->actionContrast() );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ( have_output ) printf( "%c", separator );
|
||||
if ( contrast >= 0 )
|
||||
printf( "%d", monitor->actionContrast( contrast ) );
|
||||
|
@ -686,17 +622,13 @@ int main( int argc, char *argv[] )
|
|||
have_output = true;
|
||||
}
|
||||
}
|
||||
if ( function & ZMU_HUE )
|
||||
{
|
||||
if ( verbose )
|
||||
{
|
||||
if ( function & ZMU_HUE ) {
|
||||
if ( verbose ) {
|
||||
if ( hue >= 0 )
|
||||
printf( "New hue: %d\n", monitor->actionHue( hue ) );
|
||||
else
|
||||
printf( "Current hue: %d\n", monitor->actionHue() );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ( have_output ) printf( "%c", separator );
|
||||
if ( hue >= 0 )
|
||||
printf( "%d", monitor->actionHue( hue ) );
|
||||
|
@ -705,17 +637,13 @@ int main( int argc, char *argv[] )
|
|||
have_output = true;
|
||||
}
|
||||
}
|
||||
if ( function & ZMU_COLOUR )
|
||||
{
|
||||
if ( verbose )
|
||||
{
|
||||
if ( function & ZMU_COLOUR ) {
|
||||
if ( verbose ) {
|
||||
if ( colour >= 0 )
|
||||
printf( "New colour: %d\n", monitor->actionColour( colour ) );
|
||||
else
|
||||
printf( "Current colour: %d\n", monitor->actionColour() );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ( have_output ) printf( "%c", separator );
|
||||
if ( colour >= 0 )
|
||||
printf( "%d", monitor->actionColour( colour ) );
|
||||
|
@ -724,26 +652,19 @@ int main( int argc, char *argv[] )
|
|||
have_output = true;
|
||||
}
|
||||
}
|
||||
if ( have_output )
|
||||
{
|
||||
if ( have_output ) {
|
||||
printf( "\n" );
|
||||
}
|
||||
if ( !function )
|
||||
{
|
||||
if ( !function ) {
|
||||
Usage();
|
||||
}
|
||||
delete monitor;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fprintf( stderr, "Error, invalid monitor id %d\n", mon_id );
|
||||
exit( -1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( function & ZMU_QUERY )
|
||||
{
|
||||
} else {
|
||||
if ( function & ZMU_QUERY ) {
|
||||
#if ZM_HAS_V4L
|
||||
char vidString[0x10000] = "";
|
||||
bool ok = LocalCamera::GetCurrentSettings( device, vidString, v4lVersion, verbose );
|
||||
|
@ -755,24 +676,20 @@ int main( int argc, char *argv[] )
|
|||
#endif // ZM_HAS_V4L
|
||||
}
|
||||
|
||||
if ( function & ZMU_LIST )
|
||||
{
|
||||
if ( function & ZMU_LIST ) {
|
||||
std::string sql = "select Id, Function+0 from Monitors";
|
||||
if ( !verbose )
|
||||
{
|
||||
if ( !verbose ) {
|
||||
sql += "where Function != 'None'";
|
||||
}
|
||||
sql += " order by Id asc";
|
||||
|
||||
if ( mysql_query( &dbconn, sql.c_str() ) )
|
||||
{
|
||||
if ( mysql_query( &dbconn, sql.c_str() ) ) {
|
||||
Error( "Can't run query: %s", mysql_error( &dbconn ) );
|
||||
exit( mysql_errno( &dbconn ) );
|
||||
}
|
||||
|
||||
MYSQL_RES *result = mysql_store_result( &dbconn );
|
||||
if ( !result )
|
||||
{
|
||||
if ( !result ) {
|
||||
Error( "Can't use query result: %s", mysql_error( &dbconn ) );
|
||||
exit( mysql_errno( &dbconn ) );
|
||||
}
|
||||
|
@ -780,17 +697,13 @@ int main( int argc, char *argv[] )
|
|||
Debug( 1, "Got %d monitors", n_monitors );
|
||||
|
||||
printf( "%4s%5s%6s%9s%14s%6s%6s%8s%8s\n", "Id", "Func", "State", "TrgState", "LastImgTim", "RdIdx", "WrIdx", "LastEvt", "FrmRate" );
|
||||
for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ )
|
||||
{
|
||||
for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ ) {
|
||||
int mon_id = atoi(dbrow[0]);
|
||||
int function = atoi(dbrow[1]);
|
||||
if ( !user || user->canAccess( mon_id ) )
|
||||
{
|
||||
if ( function > 1 )
|
||||
{
|
||||
if ( !user || user->canAccess( mon_id ) ) {
|
||||
if ( function > 1 ) {
|
||||
Monitor *monitor = Monitor::Load( mon_id, false, Monitor::QUERY );
|
||||
if ( monitor && monitor->connect() )
|
||||
{
|
||||
if ( monitor && monitor->connect() ) {
|
||||
struct timeval tv = monitor->GetTimestamp();
|
||||
printf( "%4d%5d%6d%9d%11ld.%02ld%6d%6d%8d%8.2f\n",
|
||||
monitor->Id(),
|
||||
|
@ -805,9 +718,7 @@ int main( int argc, char *argv[] )
|
|||
);
|
||||
delete monitor;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
struct timeval tv = { 0, 0 };
|
||||
printf( "%4d%5d%6d%9d%11ld.%02ld%6d%6d%8d%8.2f\n",
|
||||
mon_id,
|
||||
|
|
|
@ -52,8 +52,6 @@ var monitorUrl = '<?php echo ( $monitor->Server()->Url() ) ?>';
|
|||
|
||||
var scale = <?php echo $scale ?>;
|
||||
|
||||
var streamSrc = "<?php echo preg_replace( '/&/', '&', $streamSrc ) ?>";
|
||||
|
||||
var statusRefreshTimeout = <?php echo 1000*ZM_WEB_REFRESH_STATUS ?>;
|
||||
var eventsRefreshTimeout = <?php echo 1000*ZM_WEB_REFRESH_EVENTS ?>;
|
||||
var imageRefreshTimeout = <?php echo 1000*ZM_WEB_REFRESH_IMAGE ?>;
|
||||
|
|
Loading…
Reference in New Issue