From 76e0782d97f8fde02c152d0c7f8e7abd5296bafa Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Sat, 1 Dec 2018 09:58:12 -0600 Subject: [PATCH 1/6] rpm pkg - update nginx config --- distros/redhat/CMakeLists.txt | 2 + distros/redhat/nginx/redirect.nginx.conf | 2 + distros/redhat/nginx/zoneminder.nginx.conf.in | 90 ++++++++++--------- distros/redhat/readme/README.nginx | 9 +- distros/redhat/zoneminder.spec | 1 + 5 files changed, 58 insertions(+), 46 deletions(-) create mode 100644 distros/redhat/nginx/redirect.nginx.conf diff --git a/distros/redhat/CMakeLists.txt b/distros/redhat/CMakeLists.txt index 716faea4c..06b0e8cbf 100644 --- a/distros/redhat/CMakeLists.txt +++ b/distros/redhat/CMakeLists.txt @@ -32,6 +32,7 @@ configure_file(httpd/com.zoneminder.systemctl.rules.httpd.in ${CMAKE_CURRENT_SOU # Configure the Nginx zoneminder files configure_file(nginx/zm-nginx.conf ${CMAKE_CURRENT_SOURCE_DIR}/zm-nginx.conf COPYONLY) configure_file(nginx/zoneminder.nginx.conf.in ${CMAKE_CURRENT_SOURCE_DIR}/zoneminder.nginx.conf @ONLY) +configure_file(nginx/redirect.nginx.conf ${CMAKE_CURRENT_SOURCE_DIR}/redirect.nginx.conf COPYONLY) configure_file(nginx/zoneminder.nginx.tmpfiles.in ${CMAKE_CURRENT_SOURCE_DIR}/zoneminder.nginx.tmpfiles.conf @ONLY) configure_file(nginx/zm-web-user.conf ${CMAKE_CURRENT_SOURCE_DIR}/zm-web-user.conf COPYONLY) configure_file(nginx/zoneminder.php-fpm.conf ${CMAKE_CURRENT_SOURCE_DIR}/zoneminder.php-fpm.conf COPYONLY) @@ -62,6 +63,7 @@ install(FILES com.zoneminder.systemctl.rules.httpd DESTINATION /etc/zm/www PERMI # Install the Nginx zoneminder files install(FILES zm-nginx.conf DESTINATION /usr/lib/systemd/system/zoneminder.service.d PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ) install(FILES zoneminder.nginx.conf DESTINATION /etc/zm/www PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ) +install(FILES redirect.nginx.conf DESTINATION /etc/zm/www PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ) install(FILES zoneminder.nginx.tmpfiles.conf DESTINATION /usr/lib/tmpfiles.d PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ) install(FILES com.zoneminder.systemctl.rules.nginx DESTINATION /etc/zm/www PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ) install(FILES zm-web-user.conf DESTINATION /etc/zm/conf.d PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ) diff --git a/distros/redhat/nginx/redirect.nginx.conf b/distros/redhat/nginx/redirect.nginx.conf new file mode 100644 index 000000000..67ef08124 --- /dev/null +++ b/distros/redhat/nginx/redirect.nginx.conf @@ -0,0 +1,2 @@ +# Auto redirect to https +return 301 https://$host$request_uri; diff --git a/distros/redhat/nginx/zoneminder.nginx.conf.in b/distros/redhat/nginx/zoneminder.nginx.conf.in index fb8141c74..c2e3edee7 100644 --- a/distros/redhat/nginx/zoneminder.nginx.conf.in +++ b/distros/redhat/nginx/zoneminder.nginx.conf.in @@ -1,53 +1,57 @@ -listen 443 ssl; -listen [::]:443 ssl; +server { + listen 443 ssl default_server; + listen [::]:443 ssl default_server; + server_name = localhost $hostname; -ssl_certificate "/etc/pki/tls/certs/localhost.crt"; -ssl_certificate_key "/etc/pki/tls/private/localhost.key"; -ssl_session_cache shared:SSL:1m; -ssl_session_timeout 10m; -ssl_ciphers PROFILE=SYSTEM; -ssl_prefer_server_ciphers on; + ssl_certificate "/etc/pki/tls/certs/localhost.crt"; + ssl_certificate_key "/etc/pki/tls/private/localhost.key"; + ssl_session_cache shared:SSL:1m; + ssl_session_timeout 10m; + ssl_ciphers PROFILE=SYSTEM; + ssl_prefer_server_ciphers on; -# Auto-redirect HTTP requests to HTTPS -if ($scheme != "https") { - rewrite ^/?(zm)(.*)$ https://$host/$1$2 permanent; -} - -location /cgi-bin-zm { - gzip off; - alias "@ZM_CGIDIR@"; - - include /etc/nginx/fastcgi_params; - fastcgi_param SCRIPT_FILENAME $request_filename; - fastcgi_pass unix:/run/fcgiwrap.sock; -} - -location /zm/cache { - alias "@ZM_CACHEDIR@"; -} - -location /zm { - gzip off; - alias "@ZM_WEBDIR@"; - index index.php; - - location ~ \.php$ { - if (!-f $request_filename) { return 404; } - expires epoch; - include /etc/nginx/fastcgi_params; - fastcgi_param SCRIPT_FILENAME $request_filename; - fastcgi_index index.php; - fastcgi_pass unix:/run/php-fpm/www.sock; + # Auto redirect to server/zm when no url suffix was given + location = / { + return 301 zm; } - location ~ \.(jpg|jpeg|gif|png|ico)$ { - access_log off; - expires 33d; + location /cgi-bin-zm { + gzip off; + alias "@ZM_CGIDIR@"; + + include /etc/nginx/fastcgi_params; + fastcgi_param SCRIPT_FILENAME $request_filename; + fastcgi_pass unix:/run/fcgiwrap.sock; } - location /zm/api/ { + location /zm/cache { + alias "@ZM_CACHEDIR@"; + } + + location /zm { + gzip off; alias "@ZM_WEBDIR@"; - rewrite ^/zm/api(.+)$ /zm/api/app/webroot/index.php?p=$1 last; + index index.php; + + location ~ \.php$ { + try_files $uri =404; + expires epoch; + include /etc/nginx/fastcgi_params; + fastcgi_param SCRIPT_FILENAME $request_filename; + fastcgi_index index.php; + fastcgi_pass unix:/run/php-fpm/www.sock; + } + + location ~ \.(jpg|jpeg|gif|png|ico)$ { + access_log off; + expires 33d; + } + + location /zm/api/ { + alias "@ZM_WEBDIR@"; + rewrite ^/zm/api(.+)$ /zm/api/app/webroot/index.php?p=$1 last; + } } + } diff --git a/distros/redhat/readme/README.nginx b/distros/redhat/readme/README.nginx index b55d26428..cca4e72c2 100644 --- a/distros/redhat/readme/README.nginx +++ b/distros/redhat/readme/README.nginx @@ -61,8 +61,7 @@ New installs 6. Configure the web server This package uses the HTTPS protocol by default to access the web portal, - using the default self signed certificate on your system. Requests using - HTTP will auto-redirect to HTTPS. + using the default self signed certificate on your system. Inspect the web server configuration file and verify it meets your needs: @@ -71,9 +70,13 @@ New installs If you are running other web enabled services then you may need to edit this file to suite. See README.https to learn about other alternatives. + If you wish http requests to auto-redirect to https requests, then link or + copy /etc/zm/www/redirect.nginx.conf into /etc/nginx/default.d folder. + When in doubt, proceed with the default: - sudo ln -sf /etc/zm/www/zoneminder.nginx.conf /etc/nginx/default.d/ + sudo ln -sf /etc/zm/www/zoneminder.nginx.conf /etc/nginx/conf.d/ + sudo ln -sf /etc/zm/www/redirect.nginx.conf /etc/nginx/default.d/ 7. Edit /etc/sysconfig/fcgiwrap and set DAEMON_PROCS to the maximum number of simulatneous streams the server should support. Generally, a good minimum diff --git a/distros/redhat/zoneminder.spec b/distros/redhat/zoneminder.spec index 59fd3dc81..734a70a25 100644 --- a/distros/redhat/zoneminder.spec +++ b/distros/redhat/zoneminder.spec @@ -390,6 +390,7 @@ EOF %config(noreplace) %attr(640,root,nginx) %{_sysconfdir}/zm/conf.d/*.conf %ghost %attr(640,root,nginx) %{_sysconfdir}/zm/conf.d/zmcustom.conf %config(noreplace) %{_sysconfdir}/zm/www/zoneminder.nginx.conf +%config(noreplace) %{_sysconfdir}/zm/www/redirect.nginx.conf %ghost %{_sysconfdir}/zm/www/zoneminder.conf %config(noreplace) %{_sysconfdir}/zm/www/com.zoneminder.systemctl.rules.nginx %ghost %{_datadir}/polkit-1/rules.d/com.zoneminder.systemctl.rules From cae6ffd5a3c781da5830fe9c8568c6275e6c4def Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Sat, 1 Dec 2018 13:27:08 -0600 Subject: [PATCH 2/6] use HTTP_HOST instead of SERVER_NAME --- web/includes/Server.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/web/includes/Server.php b/web/includes/Server.php index 3918e9389..dae6cd7c2 100644 --- a/web/includes/Server.php +++ b/web/includes/Server.php @@ -51,7 +51,8 @@ class Server { } else if ( $this->Id() ) { return $this->{'Name'}; } - return $_SERVER['SERVER_NAME']; + # Use HTTP_HOST instead of SERVER_NAME here for nginx compatiblity + return $_SERVER['HTTP_HOST']; } public function Protocol( $new = null ) { @@ -93,7 +94,8 @@ class Server { if ( $this->Id() ) { $url .= $this->Hostname(); } else { - $url .= $_SERVER['SERVER_NAME']; + # Use HTTP_HOST instead of SERVER_NAME here for nginx compatiblity + $url .= $_SERVER['HTTP_HOST']; } if ( $port ) { $url .= ':'.$port; From e327ad100eef72662b540f11c31e5b7da57e2fe3 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Sat, 1 Dec 2018 17:03:50 -0600 Subject: [PATCH 3/6] fix WebSite camera startup issue --- web/includes/actions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/includes/actions.php b/web/includes/actions.php index de0861fe0..1e560f694 100644 --- a/web/includes/actions.php +++ b/web/includes/actions.php @@ -617,7 +617,7 @@ if ( canEdit('Monitors') ) { $new_monitor = new Monitor($mid); //fixDevices(); - if ( $monitor['Type'] != 'WebSite' ) { + if ( $new_monitor->Type() != 'WebSite' ) { $new_monitor->zmcControl('start'); $new_monitor->zmaControl('start'); } From dbb51e985785062d02a30152c89ac02be2aaf46e Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Sun, 2 Dec 2018 09:40:15 -0600 Subject: [PATCH 4/6] add generic nginx config file --- misc/CMakeLists.txt | 1 + misc/nginx.conf.in | 61 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 misc/nginx.conf.in diff --git a/misc/CMakeLists.txt b/misc/CMakeLists.txt index 3f92bd5da..990b8ce06 100644 --- a/misc/CMakeLists.txt +++ b/misc/CMakeLists.txt @@ -2,6 +2,7 @@ # Create files from the .in files configure_file(apache.conf.in "${CMAKE_CURRENT_BINARY_DIR}/apache.conf" @ONLY) +configure_file(nginx.conf.in "${CMAKE_CURRENT_BINARY_DIR}/nginx.conf" @ONLY) configure_file(logrotate.conf.in "${CMAKE_CURRENT_BINARY_DIR}/logrotate.conf" @ONLY) configure_file(syslog.conf.in "${CMAKE_CURRENT_BINARY_DIR}/syslog.conf" @ONLY) configure_file(com.zoneminder.systemctl.policy.in "${CMAKE_CURRENT_BINARY_DIR}/com.zoneminder.systemctl.policy" @ONLY) diff --git a/misc/nginx.conf.in b/misc/nginx.conf.in new file mode 100644 index 000000000..47dc3ce68 --- /dev/null +++ b/misc/nginx.conf.in @@ -0,0 +1,61 @@ +# +# PLEASE NOTE THAT THIS FILE IS INTENDED FOR GUIDANCE ONLY AND MAY NOT BE APPROPRIATE FOR YOUR DISTRIBUTION +# + +server { + listen 443 ssl default_server; + listen [::]:443 ssl default_server; + server_name = localhost $hostname; + + ssl_certificate "/etc/pki/tls/certs/localhost.crt"; + ssl_certificate_key "/etc/pki/tls/private/localhost.key"; + ssl_session_cache shared:SSL:1m; + ssl_session_timeout 10m; + ssl_ciphers PROFILE=SYSTEM; + ssl_prefer_server_ciphers on; + + # Auto redirect to server/zm when no url suffix was given + location = / { + return 301 zm; + } + + location /cgi-bin-zm { + gzip off; + alias "@ZM_CGIDIR@"; + + include /etc/nginx/fastcgi_params; + fastcgi_param SCRIPT_FILENAME $request_filename; + fastcgi_pass unix:/run/fcgiwrap.sock; + } + + location /zm/cache { + alias "@ZM_CACHEDIR@"; + } + + location /zm { + gzip off; + alias "@ZM_WEBDIR@"; + index index.php; + + location ~ \.php$ { + try_files $uri =404; + expires epoch; + include /etc/nginx/fastcgi_params; + fastcgi_param SCRIPT_FILENAME $request_filename; + fastcgi_index index.php; + fastcgi_pass unix:/run/php-fpm/www.sock; + } + + location ~ \.(jpg|jpeg|gif|png|ico)$ { + access_log off; + expires 33d; + } + + location /zm/api/ { + alias "@ZM_WEBDIR@"; + rewrite ^/zm/api(.+)$ /zm/api/app/webroot/index.php?p=$1 last; + } + } + +} + From d837b4283632aa6c39efaca09561acdfc6abb1b2 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 3 Dec 2018 10:33:53 -0500 Subject: [PATCH 5/6] fix ffmpeg warnings. We have to copy parameters from the context to the stream AFTER we open the codec --- src/zm_videostore.cpp | 124 ++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 76 deletions(-) diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index a3b66646b..746036efe 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -238,7 +238,7 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in, avformat_new_stream(oc, (AVCodec *)audio_in_ctx->codec); #endif if ( !audio_out_stream ) { - Error("Unable to create audio out stream\n"); + Error("Unable to create audio out stream"); audio_out_stream = NULL; } else { Debug(2, "setting parameters"); @@ -265,7 +265,6 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in, Debug(2, "Setting audio codec tag to %d", audio_out_ctx->codec_tag); } - #else audio_out_ctx = audio_out_stream->codec; ret = avcodec_copy_context(audio_out_ctx, audio_in_ctx); @@ -287,7 +286,7 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in, } // end if is AAC if ( audio_out_stream ) { - if (oc->oformat->flags & AVFMT_GLOBALHEADER) { + if ( oc->oformat->flags & AVFMT_GLOBALHEADER ) { #if LIBAVCODEC_VERSION_CHECK(56, 35, 0, 64, 0) audio_out_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; #else @@ -297,7 +296,6 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in, } } // end if audio_in_stream - video_last_pts = 0; video_last_dts = 0; audio_last_pts = 0; @@ -310,12 +308,11 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in, bool VideoStore::open() { /* open the out file, if needed */ - if (!(out_format->flags & AVFMT_NOFILE)) { + if ( !(out_format->flags & AVFMT_NOFILE) ) { ret = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE, NULL, NULL); - if (ret < 0) { + if ( ret < 0 ) { Error("Could not open out file '%s': %s\n", filename, av_make_error_string(ret).c_str()); - return false; } } @@ -339,9 +336,9 @@ bool VideoStore::open() { } else if (av_dict_count(opts) != 0) { Warning("some options not set\n"); } - if (opts) av_dict_free(&opts); - if (ret < 0) { - Error("Error occurred when writing out file header to %s: %s\n", + if ( opts ) av_dict_free(&opts); + if ( ret < 0 ) { + Error("Error occurred when writing out file header to %s: %s", filename, av_make_error_string(ret).c_str()); /* free the stream */ avio_closep(&oc->pb); @@ -506,13 +503,13 @@ bool VideoStore::setup_resampler() { avcodec_find_decoder(audio_in_ctx->codec_id); #endif ret = avcodec_open2(audio_in_ctx, audio_in_codec, NULL); - if (ret < 0) { + if ( ret < 0 ) { Error("Can't open in codec!"); return false; } audio_out_codec = avcodec_find_encoder(AV_CODEC_ID_AAC); - if (!audio_out_codec) { + if ( !audio_out_codec ) { Error("Could not find codec for AAC"); return false; } @@ -521,7 +518,6 @@ bool VideoStore::setup_resampler() { #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) // audio_out_ctx = audio_out_stream->codec; audio_out_ctx = avcodec_alloc_context3(audio_out_codec); - if ( !audio_out_ctx ) { Error("could not allocate codec ctx for AAC"); audio_out_stream = NULL; @@ -530,7 +526,7 @@ bool VideoStore::setup_resampler() { Debug(2, "Have audio_out_ctx"); // Now copy them to the out stream - audio_out_stream = avformat_new_stream(oc, NULL); + audio_out_stream = avformat_new_stream(oc, audio_out_codec); #else audio_out_stream = avformat_new_stream(oc, NULL); audio_out_ctx = audio_out_stream->codec; @@ -554,28 +550,27 @@ bool VideoStore::setup_resampler() { audio_out_ctx->channel_layout = av_get_default_channel_layout(audio_out_ctx->channels); } - if (audio_out_codec->supported_samplerates) { + if ( audio_out_codec->supported_samplerates ) { int found = 0; - for (unsigned int i = 0; audio_out_codec->supported_samplerates[i]; - i++) { - if (audio_out_ctx->sample_rate == - audio_out_codec->supported_samplerates[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; break; } } - if (found) { + if ( found ) { Debug(3, "Sample rate is good"); } else { audio_out_ctx->sample_rate = audio_out_codec->supported_samplerates[0]; - Debug(1, "Sampel rate is no good, setting to (%d)", + Debug(1, "Sample rate is no good, setting to (%d)", audio_out_codec->supported_samplerates[0]); } } /* check that the encoder supports s16 pcm in */ - if (!check_sample_fmt(audio_out_codec, audio_out_ctx->sample_fmt)) { + if ( !check_sample_fmt(audio_out_codec, audio_out_ctx->sample_fmt) ) { Debug(3, "Encoder does not support sample format %s, setting to FLTP", av_get_sample_fmt_name(audio_out_ctx->sample_fmt)); audio_out_ctx->sample_fmt = AV_SAMPLE_FMT_FLTP; @@ -584,16 +579,6 @@ bool VideoStore::setup_resampler() { audio_out_ctx->time_base = (AVRational){1, audio_out_ctx->sample_rate}; - -#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) - ret = avcodec_parameters_from_context(audio_out_stream->codecpar, - audio_out_ctx); - if (ret < 0) { - Error("Could not initialize stream parameteres"); - return false; - } -#endif - AVDictionary *opts = NULL; if ( (ret = av_dict_set(&opts, "strict", "experimental", 0)) < 0 ) { Error("Couldn't set experimental"); @@ -608,6 +593,15 @@ bool VideoStore::setup_resampler() { return false; } +#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) + ret = avcodec_parameters_from_context( + audio_out_stream->codecpar, audio_out_ctx); + if ( ret < 0 ) { + Error("Could not initialize stream parameteres"); + return false; + } +#endif + Debug(1, "Audio out bit_rate (%d) sample_rate(%d) channels(%d) fmt(%d) " "layout(%d) frame_size(%d)", @@ -616,13 +610,13 @@ bool VideoStore::setup_resampler() { audio_out_ctx->channel_layout, audio_out_ctx->frame_size); /** Create a new frame to store the audio samples. */ - if (!(in_frame = zm_av_frame_alloc())) { + if ( !(in_frame = zm_av_frame_alloc()) ) { Error("Could not allocate in frame"); return false; } /** Create a new frame to store the audio samples. */ - if (!(out_frame = zm_av_frame_alloc())) { + if ( !(out_frame = zm_av_frame_alloc()) ) { Error("Could not allocate out frame"); av_frame_free(&in_frame); return false; @@ -630,20 +624,20 @@ bool VideoStore::setup_resampler() { // Setup the audio resampler resample_ctx = avresample_alloc_context(); - if (!resample_ctx) { - Error("Could not allocate resample ctx\n"); + if ( !resample_ctx ) { + Error("Could not allocate resample ctx"); return false; } // Some formats (i.e. WAV) do not produce the proper channel layout - if (audio_in_ctx->channel_layout == 0) { - uint64_t layout = av_get_channel_layout("mono"); - av_opt_set_int(resample_ctx, "in_channel_layout", - av_get_channel_layout("mono"), 0); - Debug(1, "Bad channel layout. Need to set it to mono (%d).", layout); + uint64_t layout = av_get_channel_layout("mono"); + if ( audio_in_ctx->channel_layout == 0 ) { + av_opt_set_int(resample_ctx, "in_channel_layout", layout, 0); + Debug(1, "Bad in channel layout. Need to set it to mono (%d).", layout); } else { av_opt_set_int(resample_ctx, "in_channel_layout", audio_in_ctx->channel_layout, 0); + layout = audio_in_ctx->channel_layout; } av_opt_set_int(resample_ctx, "in_sample_fmt", @@ -655,7 +649,7 @@ bool VideoStore::setup_resampler() { // av_opt_set_int( resample_ctx, "out_channel_layout", // audio_out_ctx->channel_layout, 0); av_opt_set_int(resample_ctx, "out_channel_layout", - av_get_channel_layout("mono"), 0); + layout, 0); av_opt_set_int(resample_ctx, "out_sample_fmt", audio_out_ctx->sample_fmt, 0); av_opt_set_int(resample_ctx, "out_sample_rate", @@ -664,38 +658,13 @@ bool VideoStore::setup_resampler() { audio_out_ctx->channels, 0); ret = avresample_open(resample_ctx); - if (ret < 0) { - Error("Could not open resample ctx\n"); + if ( ret < 0 ) { + Error("Could not open resample ctx"); return false; + } else { + Debug(2, "Success opening resampler"); } -#if 0 - /** - * Allocate as many pointers as there are audio channels. - * Each pointer will later point to the audio samples of the corresponding - * channels (although it may be NULL for interleaved formats). - */ - if (!( converted_in_samples = reinterpret_castcalloc( audio_out_ctx->channels, sizeof(*converted_in_samples))) ) { - Error("Could not allocate converted in sample pointers\n"); - return; - } - /** - * Allocate memory for the samples of all channels in one consecutive - * block for convenience. - */ - if ( (ret = av_samples_alloc( &converted_in_samples, NULL, - audio_out_ctx->channels, - audio_out_ctx->frame_size, - audio_out_ctx->sample_fmt, 0)) < 0 ) { - Error("Could not allocate converted in samples (error '%s')\n", - av_make_error_string(ret).c_str()); - - av_freep(converted_in_samples); - free(converted_in_samples); - return; - } -#endif - out_frame->nb_samples = audio_out_ctx->frame_size; out_frame->format = audio_out_ctx->sample_fmt; out_frame->channel_layout = audio_out_ctx->channel_layout; @@ -703,21 +672,24 @@ bool VideoStore::setup_resampler() { // The codec gives us the frame size, in samples, we calculate the size of the // samples buffer in bytes unsigned int audioSampleBuffer_size = av_samples_get_buffer_size( - NULL, audio_out_ctx->channels, audio_out_ctx->frame_size, + NULL, audio_out_ctx->channels, + audio_out_ctx->frame_size, audio_out_ctx->sample_fmt, 0); converted_in_samples = (uint8_t *)av_malloc(audioSampleBuffer_size); - if (!converted_in_samples) { - Error("Could not allocate converted in sample pointers\n"); + if ( !converted_in_samples ) { + Error("Could not allocate converted in sample pointers"); return false; + } else { + Debug(2, "Frame Size %d, sample buffer size %d", audio_out_ctx->frame_size, audioSampleBuffer_size); } // Setup the data pointers in the AVFrame - if (avcodec_fill_audio_frame(out_frame, audio_out_ctx->channels, + if ( avcodec_fill_audio_frame(out_frame, audio_out_ctx->channels, audio_out_ctx->sample_fmt, (const uint8_t *)converted_in_samples, audioSampleBuffer_size, 0) < 0) { - Error("Could not allocate converted in sample pointers\n"); + Error("Could not allocate converted in sample pointers"); return false; } From f2f1e230d14232e7bc1737d8d109d601e48c2792 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 3 Dec 2018 16:25:03 -0500 Subject: [PATCH 6/6] put back missing ! --- scripts/ZoneMinder/lib/ZoneMinder/Database.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Database.pm b/scripts/ZoneMinder/lib/ZoneMinder/Database.pm index dcc797bd4..173c0033c 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Database.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Database.pm @@ -208,7 +208,7 @@ sub zmDbGetMonitor { return undef; } my $res = $sth->execute($id); - if ( $res ) { + if ( !$res ) { Error("Can't execute '$sql': ".$sth->errstr()); return undef; }