wip
This commit is contained in:
parent
106351a9f3
commit
d1886b5536
|
@ -36,10 +36,10 @@ int AnalysisThread::run() {
|
|||
}
|
||||
|
||||
if ( !monitor->Analyse() ) {
|
||||
//Debug(4, "Sleeping for %d", monitor->Active()?ZM_SAMPLE_RATE:ZM_SUSPENDED_RATE);
|
||||
Debug(2, "Sleeping for %d", monitor->Active()?ZM_SAMPLE_RATE:ZM_SUSPENDED_RATE);
|
||||
usleep(monitor->Active()?ZM_SAMPLE_RATE:ZM_SUSPENDED_RATE);
|
||||
} else if ( analysis_rate ) {
|
||||
//Debug(4, "Sleeping for %d", analysis_rate);
|
||||
Debug(2, "Sleeping for %d", analysis_rate);
|
||||
usleep(analysis_rate);
|
||||
}
|
||||
|
||||
|
|
|
@ -799,10 +799,10 @@ double Monitor::GetFPS() const {
|
|||
useconds_t Monitor::GetAnalysisRate() {
|
||||
capture_fps = GetFPS();
|
||||
if ( !analysis_fps_limit ) {
|
||||
return( 0 );
|
||||
return 0;
|
||||
} else if ( analysis_fps_limit > capture_fps ) {
|
||||
Warning( "Analysis fps (%.2f) is greater than capturing fps (%.2f)", analysis_fps_limit, capture_fps );
|
||||
return( 0 );
|
||||
return 0;
|
||||
} else {
|
||||
return( ( 1000000 / analysis_fps_limit ) - ( 1000000 / capture_fps ) );
|
||||
}
|
||||
|
@ -1241,14 +1241,23 @@ bool Monitor::Analyse() {
|
|||
|
||||
// If do have an event, then analysis_it should point to the head of the queue, because we would have emptied it on event creation.
|
||||
unsigned int index = ( shared_data->last_read_index + 1 ) % image_buffer_count;
|
||||
Debug(2, "Analysis index (%d), last_Write(%d)", index, shared_data->last_write_index );
|
||||
if ( analysis_it == packetqueue.pktQueue.end() ) {
|
||||
Debug(2, "Analysis index (%d), last_Write(%d), at end of queue", index, shared_data->last_write_index );
|
||||
}
|
||||
// Move to next packet.
|
||||
while ( ( index != shared_data->last_write_index ) && ( analysis_it != packetqueue.pktQueue.end() ) ) {
|
||||
while ( ( index != shared_data->last_write_index ) && ( *analysis_it != packetqueue.pktQueue.back() ) ) {
|
||||
++analysis_it;
|
||||
|
||||
ZMPacket *snap = *analysis_it;
|
||||
struct timeval *timestamp = snap->timestamp;
|
||||
Image *snap_image = snap->image;
|
||||
Debug(2, "Analysing image (%d)", snap->image_index );
|
||||
if ( snap->image_index == -1 ) {
|
||||
Debug(2, "skipping because audio");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
int last_section_mod = 0;
|
||||
|
||||
|
@ -1306,7 +1315,9 @@ bool Monitor::Analyse() {
|
|||
shared_data->active = signal;
|
||||
ref_image = *snap_image;
|
||||
|
||||
} else if ( signal ) {
|
||||
}// else
|
||||
|
||||
if ( signal ) {
|
||||
if ( Active() && (function == MODECT || function == MOCORD) ) {
|
||||
Debug(3, "signal and active and modect");
|
||||
Event::StringSet zoneSet;
|
||||
|
@ -1466,12 +1477,12 @@ bool Monitor::Analyse() {
|
|||
} // analsys_images or record stats
|
||||
|
||||
mutex.lock();
|
||||
snap = packetqueue.popPacket();
|
||||
ZMPacket *pack = packetqueue.popPacket();
|
||||
mutex.unlock();
|
||||
event->AddPacket( snap, score );
|
||||
if ( snap->image_index == -1 ) {
|
||||
delete snap;
|
||||
snap = NULL;
|
||||
event->AddPacket( pack, score );
|
||||
if ( pack->image_index == -1 ) {
|
||||
delete pack;
|
||||
pack = NULL;
|
||||
}
|
||||
|
||||
if ( noteSetMap.size() > 0 )
|
||||
|
@ -1479,28 +1490,28 @@ bool Monitor::Analyse() {
|
|||
} else if ( state == ALERT ) {
|
||||
// Alert means this frame has no motion, but we were alarmed and are still recording.
|
||||
mutex.lock();
|
||||
snap = packetqueue.popPacket();
|
||||
ZMPacket *pack = packetqueue.popPacket();
|
||||
mutex.unlock();
|
||||
event->AddPacket( snap, score );
|
||||
if ( snap->image_index == -1 ) {
|
||||
delete snap;
|
||||
snap = NULL;
|
||||
event->AddPacket( pack, score );
|
||||
if ( pack->image_index == -1 ) {
|
||||
delete pack;
|
||||
pack = NULL;
|
||||
}
|
||||
if ( noteSetMap.size() > 0 )
|
||||
event->updateNotes( noteSetMap );
|
||||
} else if ( state == TAPE ) {
|
||||
if ( !(image_count%(frame_skip+1)) ) {
|
||||
mutex.lock();
|
||||
snap = packetqueue.popPacket();
|
||||
ZMPacket *pack = packetqueue.popPacket();
|
||||
mutex.unlock();
|
||||
if ( config.bulk_frame_interval > 1 ) {
|
||||
event->AddPacket( snap, (event->Frames()<pre_event_count?0:-1) );
|
||||
event->AddPacket( pack, (event->Frames()<pre_event_count?0:-1) );
|
||||
} else {
|
||||
event->AddPacket( snap );
|
||||
event->AddPacket( pack );
|
||||
}
|
||||
if ( snap->image_index == -1 ) {
|
||||
delete snap;
|
||||
snap = NULL;
|
||||
if ( pack->image_index == -1 ) {
|
||||
delete pack;
|
||||
pack = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1508,7 +1519,7 @@ bool Monitor::Analyse() {
|
|||
ref_image.Blend( *snap_image, ( state==ALARM ? alarm_ref_blend_perc : ref_blend_perc ) );
|
||||
}
|
||||
last_signal = signal;
|
||||
} // end if signal change or signal
|
||||
} // end if signal
|
||||
|
||||
} else {
|
||||
Debug(3,"Not ready?");
|
||||
|
@ -1525,11 +1536,10 @@ bool Monitor::Analyse() {
|
|||
|
||||
shared_data->last_read_index = snap->image_index;
|
||||
shared_data->last_read_time = now.tv_sec;
|
||||
analysis_image_count++;
|
||||
} // end while not at end of packetqueue
|
||||
//mutex.unlock();
|
||||
|
||||
analysis_image_count++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2759,7 +2769,7 @@ int Monitor::Capture() {
|
|||
}
|
||||
|
||||
ZMPacket *packet = &image_buffer[index];
|
||||
Debug(2,"Reset index(%d)", index );
|
||||
Debug(2,"Reset index(%d) of (%d)", index, image_buffer_count );
|
||||
packet->reset();
|
||||
Image* capture_image = packet->image;
|
||||
int captureResult = 0;
|
||||
|
@ -2802,11 +2812,8 @@ int Monitor::Capture() {
|
|||
// Only queue if we have some video packets in there.
|
||||
if ( packetqueue.video_packet_count || event ) {
|
||||
// Need to copy it into another ZMPacket.
|
||||
Debug(2, "Copyingg packet");
|
||||
ZMPacket *audio_packet = new ZMPacket( *packet );
|
||||
Debug(2, "Copyingg packet");
|
||||
audio_packet->codec_type = camera->get_AudioStream()->codecpar->codec_type;
|
||||
//packet->decode( camera->get_AudioCodecContext() );
|
||||
Debug(2, "Queueing packet");
|
||||
packetqueue.queuePacket( audio_packet );
|
||||
}
|
||||
|
|
|
@ -81,13 +81,13 @@ unsigned int zm_packetqueue::clearQueue( unsigned int frames_to_keep, int stream
|
|||
// Might not be starting with a keyframe, but should always start with a keyframe
|
||||
|
||||
if ( frames_to_keep ) {
|
||||
Debug(3, "Hit end of queue, still need (%d) video keyframes", frames_to_keep );
|
||||
Debug(4, "Hit end of queue, still need (%d) video keyframes", frames_to_keep );
|
||||
} else {
|
||||
if ( it != pktQueue.rend() ) {
|
||||
Debug(2, "Not rend");
|
||||
Debug(4, "Not rend");
|
||||
|
||||
ZMPacket *zm_packet = *it;
|
||||
Debug(2, "packet %x %d", zm_packet, zm_packet->image_index);
|
||||
Debug(4, "packet %x %d", zm_packet, zm_packet->image_index);
|
||||
|
||||
AVPacket *av_packet = &(zm_packet->packet);
|
||||
while (
|
||||
|
@ -96,7 +96,7 @@ unsigned int zm_packetqueue::clearQueue( unsigned int frames_to_keep, int stream
|
|||
(( av_packet->stream_index != stream_id ) || ! ( av_packet->flags & AV_PKT_FLAG_KEY ))
|
||||
) {
|
||||
zm_packet = *it;
|
||||
Debug(2, "packet %x %d", zm_packet, zm_packet->image_index);
|
||||
Debug(4, "packet %x %d", zm_packet, zm_packet->image_index);
|
||||
++it;
|
||||
av_packet = &( (*it)->packet );
|
||||
}
|
||||
|
|
|
@ -86,10 +86,9 @@ VideoStore::VideoStore(
|
|||
video_in_stream_index = video_in_stream->index;
|
||||
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
||||
video_in_ctx = avcodec_alloc_context3(NULL);
|
||||
Debug(2, "copy to context");
|
||||
Debug(2, "copy to video_in_context");
|
||||
avcodec_parameters_to_context(video_in_ctx,
|
||||
video_in_stream->codecpar);
|
||||
Debug(2, "dump to context");
|
||||
zm_dump_codecpar( video_in_stream->codecpar );
|
||||
//video_in_ctx.codec_id = video_in_stream->codecpar.codec_id;
|
||||
#else
|
||||
|
@ -138,12 +137,10 @@ Debug(2,"Copied video context from input stream");
|
|||
avcodec_copy_context( video_out_ctx, video_in_ctx );
|
||||
#endif
|
||||
video_out_ctx->time_base = (AVRational){1, 1000000}; // microseconds as base frame rate
|
||||
// Same codec, just copy the packets, otherwise we have to decode/encode
|
||||
video_out_codec = (AVCodec *)video_in_ctx->codec;
|
||||
// Only set orientation if doing passthrough, otherwise the frame image will be rotated
|
||||
Monitor::Orientation orientation = monitor->getOrientation();
|
||||
Debug(3, "Have orientation");
|
||||
if ( orientation ) {
|
||||
Debug(3, "Have orientation");
|
||||
if ( orientation == Monitor::ROTATE_0 ) {
|
||||
} else if ( orientation == Monitor::ROTATE_90 ) {
|
||||
dsr = av_dict_set(&video_out_stream->metadata, "rotate", "90", 0);
|
||||
|
@ -175,6 +172,14 @@ Debug(2,"Copied video context from input stream");
|
|||
default:
|
||||
break;
|
||||
}
|
||||
// Same codec, just copy the packets, otherwise we have to decode/encode
|
||||
video_out_codec = avcodec_find_encoder(AV_CODEC_ID_H264);
|
||||
if ( (ret = avcodec_open2(video_out_ctx, video_out_codec, NULL)) < 0 ) {
|
||||
Warning("Can't open video codec (%s)! %s, trying h264",
|
||||
video_out_codec->name,
|
||||
av_make_error_string(ret).c_str()
|
||||
);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
|
|
Loading…
Reference in New Issue