Pass full packet to AddFrame so that we can also write other contents out
This commit is contained in:
parent
684078e72f
commit
552974c5b7
|
@ -325,7 +325,8 @@ void Event::AddPacket_(const std::shared_ptr<ZMPacket>&packet) {
|
|||
}
|
||||
|
||||
if ((packet->codec_type == AVMEDIA_TYPE_VIDEO) or packet->image) {
|
||||
AddFrame(packet->image, packet->timestamp, packet->zone_stats, packet->score, packet->analysis_image);
|
||||
//AddFrame(packet->image, packet->timestamp, packet->zone_stats, packet->score, packet->analysis_image);
|
||||
AddFrame(packet);
|
||||
}
|
||||
end_time = packet->timestamp;
|
||||
}
|
||||
|
@ -381,18 +382,15 @@ void Event::WriteDbFrames() {
|
|||
}
|
||||
} // end void Event::WriteDbFrames()
|
||||
|
||||
void Event::AddFrame(Image *image,
|
||||
SystemTimePoint timestamp,
|
||||
const std::vector<ZoneStats> &zone_stats,
|
||||
int score,
|
||||
Image *alarm_image) {
|
||||
if (timestamp.time_since_epoch() == Seconds(0)) {
|
||||
void Event::AddFrame(const std::shared_ptr<ZMPacket>&packet) {
|
||||
if (packet->timestamp.time_since_epoch() == Seconds(0)) {
|
||||
Warning("Not adding new frame, zero timestamp");
|
||||
return;
|
||||
}
|
||||
|
||||
frames++;
|
||||
Monitor::State monitor_state = monitor->GetState();
|
||||
int score = packet->score;
|
||||
|
||||
bool write_to_db = false;
|
||||
FrameType frame_type = ( ( score > 0 ) ? ALARM : (
|
||||
|
@ -405,16 +403,16 @@ void Event::AddFrame(Image *image,
|
|||
) ? BULK : NORMAL
|
||||
) );
|
||||
Debug(1, "Have frame type %s from score(%d) state %d frames %d bulk frame interval %d and mod%d",
|
||||
frame_type_names[frame_type], score, monitor->GetState(), frames, config.bulk_frame_interval, (frames % config.bulk_frame_interval));
|
||||
frame_type_names[frame_type], score, monitor_state, frames, config.bulk_frame_interval, (frames % config.bulk_frame_interval));
|
||||
|
||||
if (score < 0) score = 0;
|
||||
tot_score += score;
|
||||
|
||||
if (image) {
|
||||
if (packet->image) {
|
||||
if (save_jpegs & 1) {
|
||||
std::string event_file = stringtf(staticConfig.capture_file_format.c_str(), path.c_str(), frames);
|
||||
Debug(1, "Writing capture frame %d to %s", frames, event_file.c_str());
|
||||
if (!WriteFrameImage(image, timestamp, event_file.c_str())) {
|
||||
if (!WriteFrameImage(packet->image, packet->timestamp, event_file.c_str())) {
|
||||
Error("Failed to write frame image");
|
||||
}
|
||||
} // end if save_jpegs
|
||||
|
@ -424,7 +422,7 @@ void Event::AddFrame(Image *image,
|
|||
if ((frames == 1) || (score > max_score)) {
|
||||
write_to_db = true; // web ui might show this as thumbnail, so db needs to know about it.
|
||||
Debug(1, "Writing snapshot to %s", snapshot_file.c_str());
|
||||
WriteFrameImage(image, timestamp, snapshot_file.c_str());
|
||||
WriteFrameImage(packet->image, packet->timestamp, snapshot_file.c_str());
|
||||
} else {
|
||||
Debug(1, "Not Writing snapshot because frames %d score %d > max %d", frames, score, max_score);
|
||||
}
|
||||
|
@ -436,19 +434,37 @@ void Event::AddFrame(Image *image,
|
|||
write_to_db = true; // OD processing will need it, so the db needs to know about it
|
||||
alarm_frame_written = true;
|
||||
Debug(1, "Writing alarm image to %s", alarm_file.c_str());
|
||||
if (!WriteFrameImage(image, timestamp, alarm_file.c_str())) {
|
||||
if (!WriteFrameImage(packet->image, packet->timestamp, alarm_file.c_str())) {
|
||||
Error("Failed to write alarm frame image to %s", alarm_file.c_str());
|
||||
}
|
||||
} else {
|
||||
Debug(3, "Not Writing alarm image because alarm frame already written");
|
||||
}
|
||||
|
||||
if (alarm_image and (save_jpegs & 2)) {
|
||||
if (packet->analysis_image and (save_jpegs & 2)) {
|
||||
std::string event_file = stringtf(staticConfig.analyse_file_format.c_str(), path.c_str(), frames);
|
||||
Debug(1, "Writing analysis frame %d to %s", frames, event_file.c_str());
|
||||
if (!WriteFrameImage(alarm_image, timestamp, event_file.c_str(), true)) {
|
||||
if (!WriteFrameImage(packet->analysis_image, packet->timestamp, event_file.c_str(), true)) {
|
||||
Error("Failed to write analysis frame image to %s", event_file.c_str());
|
||||
}
|
||||
if (packet->in_frame &&
|
||||
(
|
||||
((AVPixelFormat)packet->in_frame->format == AV_PIX_FMT_YUV420P)
|
||||
||
|
||||
((AVPixelFormat)packet->in_frame->format == AV_PIX_FMT_YUVJ420P)
|
||||
)
|
||||
) {
|
||||
std::string event_file = stringtf("%s/%d-y.jpg", path.c_str(), frames);
|
||||
Image y_image(
|
||||
packet->in_frame->width,
|
||||
packet->in_frame->height,
|
||||
1, ZM_SUBPIX_ORDER_NONE,
|
||||
packet->in_frame->data[0], 0);
|
||||
if (!WriteFrameImage(&y_image, packet->timestamp, event_file.c_str(), true)) {
|
||||
Error("Failed to write y frame image to %s", event_file.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // end if is an alarm frame
|
||||
} else {
|
||||
|
@ -470,16 +486,16 @@ void Event::AddFrame(Image *image,
|
|||
}
|
||||
|
||||
if (db_frame) {
|
||||
Microseconds delta_time = std::chrono::duration_cast<Microseconds>(timestamp - start_time);
|
||||
Microseconds delta_time = std::chrono::duration_cast<Microseconds>(packet->timestamp - start_time);
|
||||
Debug(1, "Frame delta is %.2f s - %.2f s = %.2f s, score %u zone_stats.size %zu",
|
||||
FPSeconds(timestamp.time_since_epoch()).count(),
|
||||
FPSeconds(packet->timestamp.time_since_epoch()).count(),
|
||||
FPSeconds(start_time.time_since_epoch()).count(),
|
||||
FPSeconds(delta_time).count(),
|
||||
score,
|
||||
zone_stats.size());
|
||||
packet->zone_stats.size());
|
||||
|
||||
// The idea is to write out 1/sec
|
||||
frame_data.push(new Frame(id, frames, frame_type, timestamp, delta_time, score, zone_stats));
|
||||
frame_data.push(new Frame(id, frames, frame_type, packet->timestamp, delta_time, score, packet->zone_stats));
|
||||
double fps = monitor->get_capture_fps();
|
||||
if (write_to_db
|
||||
or
|
||||
|
@ -509,8 +525,8 @@ void Event::AddFrame(Image *image,
|
|||
} // end if frame_type == BULK
|
||||
} // end if db_frame
|
||||
|
||||
end_time = timestamp;
|
||||
}
|
||||
end_time = packet->timestamp;
|
||||
} // void Event::AddFrame(const std::shared_ptr<ZMPacket>&packet)
|
||||
|
||||
bool Event::SetPath(Storage *storage) {
|
||||
scheme = storage->Scheme();
|
||||
|
|
|
@ -142,11 +142,7 @@ class Event {
|
|||
|
||||
void updateNotes(const StringSetMap &stringSetMap);
|
||||
|
||||
void AddFrame(Image *image,
|
||||
SystemTimePoint timestamp,
|
||||
const std::vector<ZoneStats> &stats,
|
||||
int score = 0,
|
||||
Image *alarm_image = nullptr);
|
||||
void AddFrame(const std::shared_ptr<ZMPacket>&packet);
|
||||
|
||||
void Stop() {
|
||||
terminate_ = true;
|
||||
|
|
|
@ -563,16 +563,20 @@ void EventStream::processCommand(const CmdMsg *msg) {
|
|||
|
||||
struct {
|
||||
uint64_t event_id;
|
||||
Microseconds duration;
|
||||
Microseconds progress;
|
||||
//Microseconds duration;
|
||||
double duration;
|
||||
//Microseconds progress;
|
||||
double progress;
|
||||
int rate;
|
||||
int zoom;
|
||||
bool paused;
|
||||
} status_data = {};
|
||||
|
||||
status_data.event_id = event_data->event_id;
|
||||
status_data.duration = event_data->duration;
|
||||
status_data.progress = event_data->frames[curr_frame_id-1].offset;
|
||||
//status_data.duration = event_data->duration;
|
||||
status_data.duration = std::chrono::duration<double>(event_data->duration).count();
|
||||
//status_data.progress = event_data->frames[curr_frame_id-1].offset;
|
||||
status_data.progress = std::chrono::duration<double>(event_data->frames[curr_frame_id-1].offset).count();
|
||||
status_data.rate = replay_rate;
|
||||
status_data.zoom = zoom;
|
||||
status_data.paused = paused;
|
||||
|
|
Loading…
Reference in New Issue