Merge branch 'ZoneMinder:master' into janus

This commit is contained in:
Jonathan Bennett 2022-01-11 10:37:29 -06:00 committed by GitHub
commit 2729e1de22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 144 additions and 116 deletions

View File

@ -293,8 +293,7 @@ int FfmpegCamera::OpenFfmpeg() {
mFormatContext->interrupt_callback.opaque = this;
ret = avformat_open_input(&mFormatContext, mPath.c_str(), nullptr, &opts);
if ( ret != 0 )
{
if (ret != 0) {
logPrintf(Logger::ERROR + monitor->Importance(),
"Unable to open input %s due to: %s", mPath.c_str(),
av_make_error_string(ret).c_str());
@ -304,7 +303,6 @@ int FfmpegCamera::OpenFfmpeg() {
mFormatContext = nullptr;
}
av_dict_free(&opts);
return -1;
}
AVDictionaryEntry *e = nullptr;

View File

@ -3306,9 +3306,9 @@ void neon32_armv7_fastblend(const uint8_t* col1, const uint8_t* col2, uint8_t* r
__attribute__((noinline)) void neon64_armv8_fastblend(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count, double blendpercent) {
#if (defined(__aarch64__) && !defined(ZM_STRIP_NEON))
static double current_blendpercent = 0.0;
static int8_t divider = 0;
if (current_blendpercent != blendpercent) {
static int8_t divider = 0;
/* Attempt to match the blending percent to one of the possible values */
if(blendpercent < 2.34375) {
// 1.5625% blending

View File

@ -2145,8 +2145,11 @@ bool Monitor::Analyse() {
((timestamp - event->StartTime()) >= min_section_length)) {
Info("%s: %03d - Left alarm state (%" PRIu64 ") - %d(%d) images",
name.c_str(), analysis_image_count, event->Id(), event->Frames(), event->AlarmFrames());
//if ( function != MOCORD || event_close_mode == CLOSE_ALARM || event->Cause() == SIGNAL_CAUSE )
if ( (function != RECORD && function != MOCORD ) || event_close_mode == CLOSE_ALARM ) {
if (
(function != RECORD && function != MOCORD)
||
(event_close_mode == CLOSE_ALARM || event_close_mode==CLOSE_IDLE)
) {
shared_data->state = state = IDLE;
Info("%s: %03d - Closing event %" PRIu64 ", alarm end%s",
name.c_str(), analysis_image_count, event->Id(), (function==MOCORD)?", section truncated":"" );

View File

@ -50,7 +50,14 @@ void VideoStream::SetupFormat( ) {
Debug(1, "Using output format: %s (%s)", of->name, of->long_name);
}
void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int height, int bitrate, double frame_rate ) {
int VideoStream::SetupCodec(
int colours,
int subpixelorder,
int width,
int height,
int bitrate,
double frame_rate
) {
/* ffmpeg format matching */
switch (colours) {
case ZM_COLOUR_RGB24:
@ -114,23 +121,21 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei
if (codec_id != AV_CODEC_ID_NONE) {
codec = avcodec_find_encoder(codec_id);
if (!codec) {
Fatal("Could not find encoder for '%s'", avcodec_get_name(codec_id));
Error("Could not find encoder for '%s'", avcodec_get_name(codec_id));
return -1;
}
Debug(1, "Found encoder for '%s'", avcodec_get_name(codec_id));
ost = avformat_new_stream(ofc, codec);
if (!ost) {
Fatal( "Could not alloc stream" );
return;
Error("Could not alloc stream");
return -1;
}
Debug(1, "Allocated stream (%d) !=? (%d)", ost->id , ofc->nb_streams - 1);
ost->id = ofc->nb_streams - 1;
codec_context = avcodec_alloc_context3(nullptr);
//avcodec_parameters_to_context(codec_context, ost->codecpar);
codec_context->codec_id = codec->id;
codec_context->codec_type = codec->type;
@ -155,8 +160,6 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei
codec_context->time_base.num = 1;
ost->time_base.den = frame_rate;
ost->time_base.num = 1;
Debug( 1, "Will encode in %d fps. %dx%d", codec_context->time_base.den, width, height );
/* emit one intra frame every second */
@ -169,8 +172,10 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei
avcodec_parameters_from_context(ost->codecpar, codec_context);
zm_dump_codecpar(ost->codecpar);
} else {
Fatal( "of->video_codec == AV_CODEC_ID_NONE" );
Error("of->video_codec == AV_CODEC_ID_NONE");
return -1;
}
return 0;
}
void VideoStream::SetParameters( ) {
@ -461,7 +466,6 @@ double VideoStream::EncodeFrame( const uint8_t *buffer, int buffer_size, bool _a
}
double VideoStream::ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size, bool add_timestamp, unsigned int timestamp ) {
if ( codec_context->pix_fmt != pf ) {
static struct SwsContext *img_convert_ctx = nullptr;
memcpy( tmp_opicture->data[0], buffer, buffer_size );
@ -494,8 +498,7 @@ double VideoStream::ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size,
int ret = avcodec_receive_packet(codec_context, pkt);
if (ret < 0) {
if (AVERROR_EOF != ret) {
Error("ERror encoding video (%d) (%s)", ret,
av_err2str(ret));
Error("ERror encoding video (%d) (%s)", ret, av_err2str(ret));
}
} else {
got_packet = 1;
@ -518,14 +521,13 @@ double VideoStream::ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size,
}
}
return ( opicture_ptr->pts);
return opicture_ptr->pts;
}
int VideoStream::SendPacket(AVPacket *packet) {
int ret = av_write_frame(ofc, packet);
if ( ret != 0 ) {
Fatal( "Error %d while writing video frame: %s", ret, av_err2str( errno ) );
if (ret < 0) {
Error("Error %d while writing video frame: %s", ret, av_err2str(errno));
}
av_packet_unref(packet);
return ret;

View File

@ -68,7 +68,7 @@ protected:
static void Initialise();
void SetupFormat( );
void SetupCodec( int colours, int subpixelorder, int width, int height, int bitrate, double frame_rate );
int SetupCodec( int colours, int subpixelorder, int width, int height, int bitrate, double frame_rate );
void SetParameters();
void ActuallyOpenStream();
double ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size, bool add_timestamp=false, unsigned int timestamp=0 );

View File

@ -21,7 +21,7 @@ class ZoneMinderDeviceSource;
class BaseServerMediaSubsession {
public:
BaseServerMediaSubsession(StreamReplicator* replicator):
explicit BaseServerMediaSubsession(StreamReplicator* replicator):
m_replicator(replicator) {};
FramedSource* createSource(

View File

@ -157,7 +157,6 @@ Image *StreamBase::prepareImage(Image *image) {
int disp_image_width = (image->Width() * scale) / ZM_SCALE_BASE, disp_image_height = (image->Height() * scale) / ZM_SCALE_BASE;
int last_disp_image_width = (image->Width() * last_scale) / ZM_SCALE_BASE, last_disp_image_height = (image->Height() * last_scale) / ZM_SCALE_BASE;
int send_image_width = (disp_image_width * act_mag ) / mag, send_image_height = (disp_image_height * act_mag ) / mag;
int last_send_image_width = (last_disp_image_width * last_act_mag ) / last_mag, last_send_image_height = (last_disp_image_height * last_act_mag ) / last_mag;
Debug(3,
"Scaling by %d, zooming by %d = magnifying by %d(%d)\n"
@ -169,8 +168,7 @@ Image *StreamBase::prepareImage(Image *image) {
"Last actual image width = %d, height = %d\n"
"Display image width = %d, height = %d\n"
"Last display image width = %d, height = %d\n"
"Send image width = %d, height = %d\n"
"Last send image width = %d, height = %d\n",
"Send image width = %d, height = %d\n",
scale, zoom, mag, act_mag,
last_scale, last_zoom, last_mag, last_act_mag,
base_image_width, base_image_height,
@ -180,8 +178,7 @@ Image *StreamBase::prepareImage(Image *image) {
last_act_image_width, last_act_image_height,
disp_image_width, disp_image_height,
last_disp_image_width, last_disp_image_height,
send_image_width, send_image_height,
last_send_image_width, last_send_image_height
send_image_width, send_image_height
);
if ( ( mag != ZM_SCALE_BASE ) && (act_mag != ZM_SCALE_BASE) ) {

View File

@ -22,7 +22,14 @@
#include "zm_image.h"
#include "zm_logger.h"
SWScale::SWScale() : gotdefaults(false), swscale_ctx(nullptr), input_avframe(nullptr), output_avframe(nullptr) {
SWScale::SWScale() :
gotdefaults(false),
swscale_ctx(nullptr),
input_avframe(nullptr),
output_avframe(nullptr),
default_width(0),
default_height(0)
{
Debug(4, "SWScale object created");
}

View File

@ -122,13 +122,14 @@ std::string stringtf(const char* format, ...) {
va_start(args, format);
va_list args2;
va_copy(args2, args);
int size = vsnprintf(nullptr, 0, format, args) + 1; // Extra space for '\0'
int size = vsnprintf(nullptr, 0, format, args);
va_end(args);
if (size <= 0) {
if (size < 0) {
va_end(args2);
throw std::runtime_error("Error during formatting.");
}
size += 1; // Extra space for '\0'
std::unique_ptr<char[]> buf(new char[size]);
vsnprintf(buf.get(), size, format, args2);
@ -259,6 +260,8 @@ void HwCapsDetect() {
unsigned long auxval = 0;
elf_aux_info(AT_HWCAP, &auxval, sizeof(auxval));
if (auxval & HWCAP_NEON) {
#else
{
#error Unsupported OS.
#endif
Debug(1,"Detected ARM (AArch32) processor with Neon");

View File

@ -401,6 +401,10 @@ bool VideoStore::open() {
} else {
audio_in_ctx = avcodec_alloc_context3(audio_out_codec);
ret = avcodec_parameters_to_context(audio_in_ctx, audio_in_stream->codecpar);
if (ret < 0)
Error("Failure from avcodec_parameters_to_context %s",
av_make_error_string(ret).c_str());
audio_in_ctx->time_base = audio_in_stream->time_base;
audio_out_ctx = avcodec_alloc_context3(audio_out_codec);
@ -497,8 +501,16 @@ bool VideoStore::open() {
Debug(1, "using movflags %s", movflags_entry->value);
}
if ((ret = avformat_write_header(oc, &opts)) < 0) {
Warning("Unable to set movflags trying with defaults.");
// we crash if we try again
if (ENOSPC != ret) {
Warning("Unable to set movflags trying with defaults.%d %s",
ret, av_make_error_string(ret).c_str());
ret = avformat_write_header(oc, nullptr);
Debug(1, "Done %d", ret);
} else {
Error("ENOSPC. fail");
}
} else if (av_dict_count(opts) != 0) {
Info("some options not used, turn on debugging for a list.");
AVDictionaryEntry *e = nullptr;
@ -729,7 +741,6 @@ bool VideoStore::setup_resampler() {
audio_out_ctx->sample_fmt = audio_in_ctx->sample_fmt;
audio_out_ctx->channels = audio_in_ctx->channels;
audio_out_ctx->channel_layout = audio_in_ctx->channel_layout;
audio_out_ctx->sample_fmt = audio_in_ctx->sample_fmt;
if (!audio_out_ctx->channel_layout) {
Debug(3, "Correcting channel layout from (%" PRIi64 ") to (%" PRIi64 ")",
audio_out_ctx->channel_layout,
@ -852,7 +863,7 @@ bool VideoStore::setup_resampler() {
return false;
}
if ((ret = swr_init(resample_ctx)) < 0) {
Error("Could not open resampler");
Error("Could not open resampler %d", ret);
av_frame_free(&in_frame);
av_frame_free(&out_frame);
swr_free(&resample_ctx);

View File

@ -219,7 +219,7 @@ bool Zone::CheckAlarms(const Image *delta_image) {
int alarm_mid_x = -1;
int alarm_mid_y = -1;
unsigned int lo_x = polygon.Extent().Lo().x_;
//unsigned int lo_x = polygon.Extent().Lo().x_;
unsigned int lo_y = polygon.Extent().Lo().y_;
unsigned int hi_x = polygon.Extent().Hi().x_;
unsigned int hi_y = polygon.Extent().Hi().y_;
@ -699,6 +699,7 @@ bool Zone::CheckAlarms(const Image *delta_image) {
if ((type < PRECLUSIVE) && (check_method >= BLOBS) && (monitor->GetOptSaveJPEGs() > 1)) {
unsigned int lo_x = polygon.Extent().Lo().x_;
// First mask out anything we don't want
for (unsigned int y = lo_y; y <= hi_y; y++) {
pdiff = diff_buff + ((diff_width * y) + lo_x);

View File

@ -88,10 +88,16 @@ function initialAlarmCues(eventId) {
}
function setAlarmCues(data) {
if (!data) {
Error('No data in setAlarmCues for event ' + eventData.Id);
} else if (!data.frames) {
Error('No data.frames in setAlarmCues for event ' + eventData.Id);
} else {
cueFrames = data.frames;
alarmSpans = renderAlarmCues(vid ? $j("#videoobj") : $j("#evtStream"));//use videojs width or zms width
$j(".alarmCue").html(alarmSpans);
}
}
function renderAlarmCues(containerEl) {
if ( !( cueFrames && cueFrames.length ) ) {