From 14460469cdcb4e51243cff5cba49cfe35d3637e4 Mon Sep 17 00:00:00 2001 From: Mr-Dave Date: Mon, 10 Jul 2023 10:31:53 -0600 Subject: [PATCH] Move av init functions to motionplus module --- src/motionplus.cpp | 60 ++++++++++++++++++++++++++++++++++++++-- src/movie.cpp | 68 ---------------------------------------------- src/movie.hpp | 5 ---- 3 files changed, 58 insertions(+), 75 deletions(-) diff --git a/src/motionplus.cpp b/src/motionplus.cpp index 7a7e9250..b8ec5c78 100644 --- a/src/motionplus.cpp +++ b/src/motionplus.cpp @@ -255,6 +255,62 @@ static void motpls_daemon() sigaction(SIGTSTP, &sig_ign_action, NULL); } +void motpls_av_log(void *ignoreme, int errno_flag, const char *fmt, va_list vl) +{ + char buf[1024]; + char *end; + int retcd; + + (void)ignoreme; + + /* Valgrind occasionally reports use of uninitialized values in here when we interrupt + * some rtsp functions. The offending value is either fmt or vl and seems to be from a + * debug level of av functions. To address it we flatten the message after we know + * the log level. Now we put the avcodec messages to INF level since their error + * are not necessarily our errors. + */ + + if (errno_flag <= AV_LOG_WARNING) { + retcd = vsnprintf(buf, sizeof(buf), fmt, vl); + if (retcd >=1024) { + MOTPLS_LOG(DBG, TYPE_ENCODER, NO_ERRNO, "av message truncated %d bytes",(retcd - 1024)); + } + end = buf + strlen(buf); + if (end > buf && end[-1] == '\n') { + *--end = 0; + } + if (strstr(buf, "Will reconnect at") == NULL) { + MOTPLS_LOG(INF, TYPE_ENCODER, NO_ERRNO, "%s", buf); + } + } + +} + +void motpls_av_init(void) +{ + MOTPLS_LOG(NTC, TYPE_ENCODER, NO_ERRNO, _("libavcodec version %d.%d.%d") + , LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR, LIBAVCODEC_VERSION_MICRO); + MOTPLS_LOG(NTC, TYPE_ENCODER, NO_ERRNO, _("libavformat version %d.%d.%d") + , LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR, LIBAVFORMAT_VERSION_MICRO); + + #if (MYFFVER < 58000) + av_register_all(); + avcodec_register_all(); + #endif + + avformat_network_init(); + avdevice_register_all(); + av_log_set_callback(motpls_av_log); + +} + +void motpls_av_deinit(void) +{ + + avformat_network_deinit(); + +} + static void motpls_shutdown(ctx_motapp *motapp) { motpls_pid_remove(motapp); @@ -646,13 +702,13 @@ static void motpls_init(ctx_motapp *motapp, int argc, char *argv[]) motpls_startup(motapp, true); - movie_global_init(); + motpls_av_init(); } static void motpls_deinit(ctx_motapp *motapp) { - movie_global_deinit(); + motpls_av_deinit(); motpls_shutdown(motapp); diff --git a/src/movie.cpp b/src/movie.cpp index 27523199..54f4319f 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -1298,39 +1298,6 @@ static int movie_passthru_open(ctx_movie *movie) return 0; } -void movie_avcodec_log(void *ignoreme, int errno_flag, const char *fmt, va_list vl) -{ - - char buf[1024]; - char *end; - int retcd; - - (void)ignoreme; - (void)errno_flag; - - /* Valgrind occasionally reports use of uninitialized values in here when we interrupt - * some rtsp functions. The offending value is either fmt or vl and seems to be from a - * debug level of av functions. To address it we flatten the message after we know - * the log level. Now we put the avcodec messages to INF level since their error - * are not necessarily our errors. - */ - - if (errno_flag <= AV_LOG_WARNING) { - retcd = vsnprintf(buf, sizeof(buf), fmt, vl); - if (retcd >=1024) { - MOTPLS_LOG(DBG, TYPE_ENCODER, NO_ERRNO, "av message truncated %d bytes",(retcd - 1024)); - } - end = buf + strlen(buf); - if (end > buf && end[-1] == '\n') { - *--end = 0; - } - if (strstr(buf, "Will reconnect at") == NULL) { - MOTPLS_LOG(INF, TYPE_ENCODER, NO_ERRNO, "%s", buf); - } - } - -} - static void movie_put_pix_yuv420(ctx_movie *movie, ctx_image_data *img_data) { unsigned char *image; @@ -1348,41 +1315,6 @@ static void movie_put_pix_yuv420(ctx_movie *movie, ctx_image_data *img_data) } -void movie_global_init(void) -{ - - MOTPLS_LOG(NTC, TYPE_ENCODER, NO_ERRNO, _("libavcodec version %d.%d.%d") - , LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR, LIBAVCODEC_VERSION_MICRO); - MOTPLS_LOG(NTC, TYPE_ENCODER, NO_ERRNO, _("libavformat version %d.%d.%d") - , LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR, LIBAVFORMAT_VERSION_MICRO); - - #if (MYFFVER < 58000) - av_register_all(); - avcodec_register_all(); - #endif - - avformat_network_init(); - avdevice_register_all(); - av_log_set_callback(movie_avcodec_log); - -} - -void movie_global_deinit(void) -{ - - avformat_network_deinit(); - - #if (MYFFVER < 58000) - /* TODO Determine if this is even needed for old versions */ - if (av_lockmgr_register(NULL) < 0) { - MOTPLS_LOG(EMG, TYPE_ALL, SHOW_ERRNO - ,_("av_lockmgr_register reset failed on cleanup")); - } - #endif - - -} - int movie_open(ctx_movie *movie) { int retcd; diff --git a/src/movie.hpp b/src/movie.hpp index 0dff18b1..c05f3777 100644 --- a/src/movie.hpp +++ b/src/movie.hpp @@ -81,11 +81,6 @@ struct ctx_movie { }; - -void movie_global_init(void); -void movie_global_deinit(void); -void movie_avcodec_log(void *, int, const char *, va_list); - int movie_open(ctx_movie *movie); int movie_put_image(ctx_movie *movie, ctx_image_data *img_data, const struct timespec *tv1); void movie_close(ctx_movie *movie);