Move av init functions to motionplus module

This commit is contained in:
Mr-Dave
2023-07-10 10:31:53 -06:00
parent d2b30e25e7
commit 14460469cd
3 changed files with 58 additions and 75 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);