Merge branch 'storageareas' into zma_to_thread

This commit is contained in:
Isaac Connor 2019-02-18 16:23:17 -05:00
commit 7d6286d517
8 changed files with 102 additions and 30 deletions

View File

@ -223,7 +223,7 @@ CREATE TABLE `Events_Hour` (
`EventId` BIGINT unsigned NOT NULL,
`MonitorId` int(10) unsigned NOT NULL,
`StartTime` datetime default NULL,
`DiskSpace` bigint unsigned default NULL,
`DiskSpace` bigint default NULL,
PRIMARY KEY (`EventId`),
KEY `Events_Hour_MonitorId_idx` (`MonitorId`),
KEY `Events_Hour_StartTime_idx` (`StartTime`)
@ -234,7 +234,7 @@ CREATE TABLE `Events_Day` (
`EventId` BIGINT unsigned NOT NULL,
`MonitorId` int(10) unsigned NOT NULL,
`StartTime` datetime default NULL,
`DiskSpace` bigint unsigned default NULL,
`DiskSpace` bigint default NULL,
PRIMARY KEY (`EventId`),
KEY `Events_Day_MonitorId_idx` (`MonitorId`),
KEY `Events_Day_StartTime_idx` (`StartTime`)
@ -245,7 +245,7 @@ CREATE TABLE `Events_Week` (
`EventId` BIGINT unsigned NOT NULL,
`MonitorId` int(10) unsigned NOT NULL,
`StartTime` datetime default NULL,
`DiskSpace` bigint unsigned default NULL,
`DiskSpace` bigint default NULL,
PRIMARY KEY (`EventId`),
KEY `Events_Week_MonitorId_idx` (`MonitorId`),
KEY `Events_Week_StartTime_idx` (`StartTime`)
@ -256,7 +256,7 @@ CREATE TABLE `Events_Month` (
`EventId` BIGINT unsigned NOT NULL,
`MonitorId` int(10) unsigned NOT NULL,
`StartTime` datetime default NULL,
`DiskSpace` bigint unsigned default NULL,
`DiskSpace` bigint default NULL,
PRIMARY KEY (`EventId`),
KEY `Events_Month_MonitorId_idx` (`MonitorId`),
KEY `Events_Month_StartTime_idx` (`StartTime`)
@ -267,7 +267,7 @@ DROP TABLE IF EXISTS `Events_Archived`;
CREATE TABLE `Events_Archived` (
`EventId` BIGINT unsigned NOT NULL,
`MonitorId` int(10) unsigned NOT NULL,
`DiskSpace` bigint unsigned default NULL,
`DiskSpace` bigint default NULL,
PRIMARY KEY (`EventId`),
KEY `Events_Archived_MonitorId_idx` (`MonitorId`)
) ENGINE=@ZM_MYSQL_ENGINE@;

13
db/zm_update-1.33.2.sql Normal file
View File

@ -0,0 +1,13 @@
--
-- This updates a 1.33.0 database to 1.33.1
--
-- Add WebSite enum to Monitor.Type
-- Add Refresh column to Monitors table
--
ALTER TABLE `Events_Hour` MODIFY DiskSpace BIGINT default NULL;
ALTER TABLE `Events_Day` MODIFY DiskSpace BIGINT default NULL;
ALTER TABLE `Events_Week` MODIFY DiskSpace BIGINT default NULL;
ALTER TABLE `Events_Month` MODIFY DiskSpace BIGINT default NULL;
ALTER TABLE `Events_Archived` MODIFY DiskSpace BIGINT default NULL;

View File

@ -696,10 +696,15 @@ sub error {
}
sub Fatal( @ ) {
fetch()->logPrint(FATAL, @_, caller);
my $this = fetch();
$this->logPrint(FATAL, @_, caller);
if ( $SIG{TERM} and ( $SIG{TERM} ne 'DEFAULT' ) ) {
$SIG{TERM}();
}
if ( $$this{sth} ) {
$$this{sth}->finish();
$$this{sth} = undef;
}
# I think if we don't disconnect we will leave sockets around in TIME_WAIT
ZoneMinder::Database::zmDbDisconnect();
exit(-1);

View File

@ -27,6 +27,7 @@ zm_packetqueue::zm_packetqueue( int video_image_count, int p_video_stream_id, in
video_packet_count = 0;
analysis_it = pktQueue.begin();
first_video_packet_index = -1;
Debug(4, "packetqueue init, first_video_packet_index is %d", first_video_packet_index);
max_stream_id = p_video_stream_id > p_audio_stream_id ? p_video_stream_id : p_audio_stream_id;
packet_counts = new int[max_stream_id+1];
@ -46,8 +47,11 @@ zm_packetqueue::~zm_packetqueue() {
*/
bool zm_packetqueue::queuePacket( ZMPacket* zm_packet ) {
Debug(4, "packetqueue queuepacket, first_video_packet_index is %d", first_video_packet_index);
if ( zm_packet->image_index != -1 ) {
// It's a video packet
// If we can never queue the same packet, then they can never go past
if ( zm_packet->image_index == first_video_packet_index ) {
Debug(2, "queuing packet that is already on the queue(%d)", zm_packet->image_index);
@ -94,6 +98,7 @@ bool zm_packetqueue::queuePacket( ZMPacket* zm_packet ) {
} else if ( first_video_packet_index == -1 ) {
// Initialize the first_video_packet indicator
first_video_packet_index = zm_packet->image_index;
video_packet_count += 1;
} // end if
} // end if queuing a video packet
@ -211,9 +216,11 @@ unsigned int zm_packetqueue::clearQueue(unsigned int frames_to_keep, int stream_
first_video_packet_index += 1;
first_video_packet_index %= max_video_packet_count;
} else {
// Re-init
first_video_packet_index = -1;
}
}
packet_counts[packet->packet.stream_index] -= 1;
pktQueue.pop_front();
if ( packet->image_index == -1 )
delete packet;

View File

@ -74,6 +74,9 @@ VideoStore::VideoStore(
out_frame = NULL;
#if defined(HAVE_LIBSWRESAMPLE) || defined(HAVE_LIBAVRESAMPLE)
resample_ctx = NULL;
#if defined(HAVE_LIBSWRESAMPLE)
fifo = NULL;
#endif
#endif
FFMPEGInit();
@ -632,6 +635,10 @@ VideoStore::~VideoStore() {
#if defined(HAVE_LIBAVRESAMPLE) || defined(HAVE_LIBSWRESAMPLE)
if ( resample_ctx ) {
#if defined(HAVE_LIBSWRESAMPLE)
if ( fifo ) {
av_audio_fifo_free(fifo);
fifo = NULL;
}
swr_free(&resample_ctx);
#else
#if defined(HAVE_LIBAVRESAMPLE)
@ -732,7 +739,7 @@ bool VideoStore::setup_resampler() {
if ( audio_out_codec->supported_samplerates ) {
int found = 0;
for ( unsigned int i = 0; audio_out_codec->supported_samplerates[i]; i++) {
for ( unsigned int i = 0; audio_out_codec->supported_samplerates[i]; i++ ) {
if ( audio_out_ctx->sample_rate ==
audio_out_codec->supported_samplerates[i] ) {
found = 1;
@ -767,7 +774,7 @@ bool VideoStore::setup_resampler() {
ret = avcodec_open2(audio_out_ctx, audio_out_codec, &opts);
av_dict_free(&opts);
if ( ret < 0 ) {
Error("could not open codec (%d) (%s)\n", ret, av_make_error_string(ret).c_str());
Error("could not open codec (%d) (%s)", ret, av_make_error_string(ret).c_str());
audio_out_codec = NULL;
audio_out_ctx = NULL;
audio_out_stream = NULL;
@ -788,6 +795,12 @@ bool VideoStore::setup_resampler() {
avcodec_copy_context( audio_out_stream->codec, audio_out_ctx );
#endif
Debug(1,
"Audio in bit_rate (%d) sample_rate(%d) channels(%d) fmt(%d) "
"layout(%d) frame_size(%d)",
audio_in_ctx->bit_rate, audio_in_ctx->sample_rate,
audio_in_ctx->channels, audio_in_ctx->sample_fmt,
audio_in_ctx->channel_layout, audio_in_ctx->frame_size);
Debug(1,
"Audio out context bit_rate (%d) sample_rate(%d) channels(%d) fmt(%d) "
"layout(%d) frame_size(%d)",
@ -828,6 +841,12 @@ bool VideoStore::setup_resampler() {
out_frame->sample_rate = audio_out_ctx->sample_rate;
#if defined(HAVE_LIBSWRESAMPLE)
if (!(fifo = av_audio_fifo_alloc(
audio_out_ctx->sample_fmt,
audio_out_ctx->channels, 1))) {
Error("Could not allocate FIFO");
return false;
}
resample_ctx = swr_alloc_set_opts(NULL,
audio_out_ctx->channel_layout,
audio_out_ctx->sample_fmt,
@ -914,7 +933,7 @@ bool VideoStore::setup_resampler() {
out_frame, audio_out_ctx->channels,
audio_out_ctx->sample_fmt,
(const uint8_t *)converted_in_samples,
audioSampleBuffer_size, 0) < 0) {
audioSampleBuffer_size, 0) < 0 ) {
Error("Could not allocate converted in sample pointers");
return false;
}
@ -1249,33 +1268,59 @@ int VideoStore::writeAudioFramePacket(ZMPacket *zm_packet) {
// Resample the in into the audioSampleBuffer until we proceed the whole
// decoded data
zm_dump_frame(in_frame, "In frame");
zm_dump_frame(out_frame, "Out frame before resample");
Debug(2, "Converting %d to %d samples", in_frame->nb_samples, out_frame->nb_samples);
#if defined(HAVE_LIBSWRESAMPLE)
#if 0
(ret = swr_convert(resample_ctx,
out_frame->data, frame_size,
(const uint8_t**)in_frame->data,
in_frame->nb_samples
))
ret = swr_convert(resample_ctx,
out_frame->data, frame_size,
(const uint8_t**)in_frame->data,
in_frame->nb_samples
);
#else
ret = swr_convert_frame(resample_ctx, out_frame, in_frame);
#endif
#else
#if defined(HAVE_LIBAVRESAMPLE)
ret = avresample_convert(resample_ctx, NULL, 0, 0, in_frame->data,
0, in_frame->nb_samples);
#endif
#endif
av_frame_unref(in_frame);
if ( ret < 0 ) {
Error("Could not resample frame (error '%s')",
av_make_error_string(ret).c_str());
return 0;
}
#endif
if ((ret = av_audio_fifo_realloc(fifo, av_audio_fifo_size(fifo) + out_frame->nb_samples)) < 0) {
Error("Could not reallocate FIFO");
return 0;
}
/** Store the new samples in the FIFO buffer. */
ret = av_audio_fifo_write(fifo, (void **)out_frame->data, out_frame->nb_samples);
if ( ret < frame_size ) {
Error("Could not write data to FIFO on %d written", ret);
return 0;
}
#if defined(HAVE_LIBAVRESAMPLE)
// Reset frame_size to output_frame_size
frame_size = audio_out_ctx->frame_size;
// AAC requires 1024 samples per encode. Our input tends to be 160, so need to buffer them.
if ( frame_size > av_audio_fifo_size(fifo) ) {
return 0;
}
if ( av_audio_fifo_read(fifo, (void **)out_frame->data, frame_size) < frame_size ) {
Error("Could not read data from FIFO");
return 0;
}
out_frame->nb_samples = frame_size;
/// FIXME this is not the correct pts
out_frame->pts = in_frame->pts;
#else
#if defined(HAVE_LIBAVRESAMPLE)
(ret = avresample_convert(resample_ctx, NULL, 0, 0, in_frame->data,
0, in_frame->nb_samples))
av_frame_unref(in_frame);
if ( ret < 0 ) {
Error("Could not resample frame (error '%s')",
av_make_error_string(ret).c_str());
return 0;
}
int samples_available = avresample_available(resample_ctx);
if ( samples_available < frame_size ) {
Debug(1, "Not enough samples yet (%d)", samples_available);
@ -1288,11 +1333,11 @@ int VideoStore::writeAudioFramePacket(ZMPacket *zm_packet) {
Warning("Error reading resampled audio:");
return 0;
}
#endif
#endif
zm_dump_frame(out_frame,"Out frame after resample");
zm_dump_frame(out_frame, "Out frame after resample");
av_init_packet(&opkt);
Debug(5, "after init packet");
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
if ( (ret = avcodec_send_frame(audio_out_ctx, out_frame)) < 0 ) {
@ -1306,7 +1351,7 @@ int VideoStore::writeAudioFramePacket(ZMPacket *zm_packet) {
if ( (ret = avcodec_receive_packet(audio_out_ctx, &opkt)) < 0 ) {
if ( AVERROR(EAGAIN) == ret ) {
// THe codec may need more samples than it has, perfectly valid
// The codec may need more samples than it has, perfectly valid
Debug(3, "Could not recieve packet (error '%s')",
av_make_error_string(ret).c_str());
} else {

View File

@ -5,6 +5,7 @@
extern "C" {
#ifdef HAVE_LIBSWRESAMPLE
#include "libswresample/swresample.h"
#include "libavutil/audio_fifo.h"
#else
#ifdef HAVE_LIBAVRESAMPLE
#include "libavresample/avresample.h"
@ -66,6 +67,7 @@ int audio_in_stream_index;
AVCodecContext *audio_out_ctx;
#ifdef HAVE_LIBSWRESAMPLE
SwrContext *resample_ctx;
AVAudioFifo *fifo;
#else
#ifdef HAVE_LIBAVRESAMPLE
AVAudioResampleContext* resample_ctx;

View File

@ -1 +1 @@
1.33.1
1.33.2

View File

@ -252,7 +252,7 @@ function getNavBarHTML($reload = null) {
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-brand"><a href="<?php echo validHtmlStr(ZM_HOME_URL); ?>" target="<?php echo validHtmlStr(ZM_WEB_TITLE); ?>"><?php echo validHtmlStr(ZM_HOME_CONTENT); ?></a></div>
<div class="navbar-brand"><a href="<?php echo validHtmlStr(ZM_HOME_URL); ?>" target="<?php echo validHtmlStr(ZM_WEB_TITLE); ?>"><?php echo ZM_HOME_CONTENT ?></a></div>
</div>
<div class="collapse navbar-collapse" id="main-header-nav">