From a9ad5c5eee6226ea08965bd2fdf5e8aab8681af3 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Sat, 5 Jun 2021 14:00:21 +0200 Subject: [PATCH] Build: Promote libavcodec to a required dependency FFmpeg is an integral component of ZM. Promote the appropriate libraries to required dependencies. This reduces the possible build configurations greatly and thus maintenance burden. --- CMakeLists.txt | 12 +----------- src/CMakeLists.txt | 1 + src/zm_eventstream.cpp | 10 +++------- src/zm_ffmpeg.h | 2 -- src/zm_monitor.h | 2 -- src/zm_monitorstream.cpp | 5 +---- src/zm_mpeg.cpp | 3 --- src/zm_mpeg.h | 4 ---- src/zm_rtp_source.cpp | 4 ---- src/zm_rtp_source.h | 4 ---- src/zm_stream.cpp | 9 ++------- src/zm_stream.h | 4 ---- src/zm_videostore.h | 5 +---- src/zms.cpp | 20 -------------------- zoneminder-config.cmake | 2 -- 15 files changed, 9 insertions(+), 78 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 41ac703c2..2940c4a85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -440,23 +440,13 @@ endif() find_package(FFMPEG REQUIRED COMPONENTS + avcodec avformat avutil) set(CMAKE_REQUIRED_INCLUDES ${FFMPEG_avutil_INCLUDE_DIRS}) check_include_file("libavutil/hwcontext.h" HAVE_LIBAVUTIL_HWCONTEXT_H) -find_package(FFMPEG COMPONENTS avcodec) -if(FFMPEG_avcodec_FOUND) - set(HAVE_LIBAVCODEC 1) - set(HAVE_LIBAVCODEC_AVCODEC_H 1) - list(APPEND ZM_BIN_LIBS "${FFMPEG_avcodec_LIBRARIES}") - set(optlibsfound "${optlibsfound} AVCodec") -else() - message(WARNING "\nWhile it should be possible to build ZM without AVCODEC the result will pretty useless.") - set(optlibsnotfound "${optlibsnotfound} AVCodec") -endif() - find_package(FFMPEG COMPONENTS avdevice) if(FFMPEG_avdevice_FOUND) set(HAVE_LIBAVDEVICE 1) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5e508e576..fe0ee23ee 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -77,6 +77,7 @@ target_include_directories(zm target_link_libraries(zm PUBLIC + FFMPEG::avcodec FFMPEG::avformat FFMPEG::avutil libbcrypt::bcrypt diff --git a/src/zm_eventstream.cpp b/src/zm_eventstream.cpp index 9b4f106e9..25949624d 100644 --- a/src/zm_eventstream.cpp +++ b/src/zm_eventstream.cpp @@ -699,7 +699,6 @@ bool EventStream::sendFrame(int delta_us) { return false; } -#if HAVE_LIBAVCODEC if ( type == STREAM_MPEG ) { Image image(filepath); @@ -712,9 +711,7 @@ bool EventStream::sendFrame(int delta_us) { vid_stream->OpenStream(); } /* double pts = */ vid_stream->EncodeFrame(send_image->Buffer(), send_image->Size(), config.mpeg_timed_frames, delta_us*1000); - } else -#endif // HAVE_LIBAVCODEC - { + } else { bool send_raw = (type == STREAM_JPEG) && ((scale>=ZM_SCALE_BASE)&&(zoom==ZM_SCALE_BASE)) && filepath[0]; fprintf(stdout, "--" BOUNDARY "\r\n"); @@ -1026,10 +1023,9 @@ void EventStream::runStream() { } // end if forward or reverse } // end if checkEventLoaded } // end while ! zm_terminate -#if HAVE_LIBAVCODEC - if ( type == STREAM_MPEG ) + if (type == STREAM_MPEG) { delete vid_stream; -#endif // HAVE_LIBAVCODEC + } closeComms(); } // end void EventStream::runStream() diff --git a/src/zm_ffmpeg.h b/src/zm_ffmpeg.h index e931b0c37..4d9715420 100644 --- a/src/zm_ffmpeg.h +++ b/src/zm_ffmpeg.h @@ -110,7 +110,6 @@ extern "C" { #endif // AVCODEC -#if HAVE_LIBAVCODEC_AVCODEC_H #include /* @@ -128,7 +127,6 @@ extern "C" { #else #define _AVCODECID CodecID #endif -#endif /* HAVE_LIBAVCODEC_AVCODEC_H */ // AVFORMAT #include diff --git a/src/zm_monitor.h b/src/zm_monitor.h index 531160885..c72b8d326 100644 --- a/src/zm_monitor.h +++ b/src/zm_monitor.h @@ -607,9 +607,7 @@ public: //void StreamImages( int scale=100, int maxfps=10, time_t ttl=0, int msq_id=0 ); //void StreamImagesRaw( int scale=100, int maxfps=10, time_t ttl=0 ); //void StreamImagesZip( int scale=100, int maxfps=10, time_t ttl=0 ); -#if HAVE_LIBAVCODEC //void StreamMpeg( const char *format, int scale=100, int maxfps=10, int bitrate=100000 ); -#endif // HAVE_LIBAVCODEC double get_capture_fps( ) const { return shared_data ? shared_data->capture_fps : 0.0; } diff --git a/src/zm_monitorstream.cpp b/src/zm_monitorstream.cpp index 0df93f963..f7ff0fea5 100644 --- a/src/zm_monitorstream.cpp +++ b/src/zm_monitorstream.cpp @@ -385,7 +385,6 @@ bool MonitorStream::sendFrame(Image *image, const timeval ×tamp) { monitor->TimestampImage(send_image, timestamp); fputs("--" BOUNDARY "\r\n", stdout); -#if HAVE_LIBAVCODEC if ( type == STREAM_MPEG ) { if ( !vid_stream ) { vid_stream = new VideoStream("pipe:", format, bitrate, effective_fps, send_image->Colours(), send_image->SubpixelOrder(), send_image->Width(), send_image->Height()); @@ -398,9 +397,7 @@ bool MonitorStream::sendFrame(Image *image, const timeval ×tamp) { base_time = timestamp; DELTA_TIMEVAL(delta_time, timestamp, base_time, DT_PREC_3); /* double pts = */ vid_stream->EncodeFrame(send_image->Buffer(), send_image->Size(), config.mpeg_timed_frames, delta_time.delta); - } else -#endif // HAVE_LIBAVCODEC - { + } else { static unsigned char temp_img_buffer[ZM_MAX_IMAGE_SIZE]; int img_buffer_size = 0; diff --git a/src/zm_mpeg.cpp b/src/zm_mpeg.cpp index 5ab1ad5dc..d73975cc7 100644 --- a/src/zm_mpeg.cpp +++ b/src/zm_mpeg.cpp @@ -24,7 +24,6 @@ #include #include -#if HAVE_LIBAVCODEC extern "C" { #include #include @@ -766,5 +765,3 @@ void *VideoStream::StreamingThreadCallback(void *ctx){ return nullptr; } - -#endif // HAVE_LIBAVCODEC diff --git a/src/zm_mpeg.h b/src/zm_mpeg.h index 4999f1328..b6a6f49be 100644 --- a/src/zm_mpeg.h +++ b/src/zm_mpeg.h @@ -23,8 +23,6 @@ #include "zm_ffmpeg.h" #include -#if HAVE_LIBAVCODEC - class VideoStream { protected: struct MimeData { @@ -83,6 +81,4 @@ public: double EncodeFrame( const uint8_t *buffer, int buffer_size, bool add_timestamp=false, unsigned int timestamp=0 ); }; -#endif // HAVE_LIBAVCODEC - #endif // ZM_MPEG_H diff --git a/src/zm_rtp_source.cpp b/src/zm_rtp_source.cpp index ff69a6069..2fd5bc41b 100644 --- a/src/zm_rtp_source.cpp +++ b/src/zm_rtp_source.cpp @@ -25,8 +25,6 @@ #include #include -#if HAVE_LIBAVCODEC - RtpSource::RtpSource( int id, const std::string &localHost, @@ -371,5 +369,3 @@ bool RtpSource::getFrame(Buffer &buffer) { Debug(4, "Copied %d bytes", buffer.size()); return true; } - -#endif // HAVE_LIBAVCODEC diff --git a/src/zm_rtp_source.h b/src/zm_rtp_source.h index 0d1bdee83..3736f71cb 100644 --- a/src/zm_rtp_source.h +++ b/src/zm_rtp_source.h @@ -29,8 +29,6 @@ #include #include -#if HAVE_LIBAVCODEC - struct RtpDataHeader; class RtpSource @@ -193,6 +191,4 @@ public: } }; -#endif // HAVE_LIBAVCODEC - #endif // ZM_RTP_SOURCE_H diff --git a/src/zm_stream.cpp b/src/zm_stream.cpp index ce7a4460b..c8f1166bd 100644 --- a/src/zm_stream.cpp +++ b/src/zm_stream.cpp @@ -28,12 +28,10 @@ #include StreamBase::~StreamBase() { -#if HAVE_LIBAVCODEC - if ( vid_stream ) { + if (vid_stream) { delete vid_stream; vid_stream = nullptr; } -#endif closeComms(); } @@ -263,7 +261,6 @@ bool StreamBase::sendTextFrame(const char *frame_text) { if ( scale != 100 ) { image.Scale(scale); } -#if HAVE_LIBAVCODEC if ( type == STREAM_MPEG ) { if ( !vid_stream ) { vid_stream = new VideoStream("pipe:", format, bitrate, effective_fps, image.Colours(), image.SubpixelOrder(), image.Width(), image.Height()); @@ -271,9 +268,7 @@ bool StreamBase::sendTextFrame(const char *frame_text) { vid_stream->OpenStream(); } /* double pts = */ vid_stream->EncodeFrame(image.Buffer(), image.Size()); - } else -#endif // HAVE_LIBAVCODEC - { + } else { static unsigned char buffer[ZM_MAX_IMAGE_SIZE]; int n_bytes = 0; diff --git a/src/zm_stream.h b/src/zm_stream.h index 6d752689d..9182d6dd4 100644 --- a/src/zm_stream.h +++ b/src/zm_stream.h @@ -129,9 +129,7 @@ protected: double last_frame_sent; struct timeval last_frame_timestamp; -#if HAVE_LIBAVCODEC VideoStream *vid_stream; -#endif // HAVE_LIBAVCODEC CmdMsg msg; @@ -178,9 +176,7 @@ public: effective_fps = 0.0; frame_mod = 1; -#if HAVE_LIBAVCODEC vid_stream = 0; -#endif // HAVE_LIBAVCODEC last_frame_sent = 0.0; last_frame_timestamp = {}; msg = { 0, { 0 } }; diff --git a/src/zm_videostore.h b/src/zm_videostore.h index 0a3f69ecf..467f85545 100644 --- a/src/zm_videostore.h +++ b/src/zm_videostore.h @@ -18,8 +18,6 @@ extern "C" { #endif } -#if HAVE_LIBAVCODEC - class Monitor; class ZMPacket; class PacketQueue; @@ -119,6 +117,5 @@ class VideoStore { void flush_codecs(); }; -#endif //havelibav -#endif //zm_videostore_h +#endif // ZM_VIDEOSTORE_H diff --git a/src/zms.cpp b/src/zms.cpp index d98f24418..70b0b1b80 100644 --- a/src/zms.cpp +++ b/src/zms.cpp @@ -281,19 +281,9 @@ int main(int argc, const char *argv[], char **envp) { } else if ( mode == ZMS_SINGLE ) { stream.setStreamType(MonitorStream::STREAM_SINGLE); } else { -#if HAVE_LIBAVCODEC stream.setStreamFormat(format); stream.setStreamBitrate(bitrate); stream.setStreamType(MonitorStream::STREAM_MPEG); -#else // HAVE_LIBAVCODEC - Error("MPEG streaming of '%s' attempted while disabled", query); - fprintf(stderr, "MPEG streaming is disabled.\n" - "You should configure with the --with-ffmpeg" - " option and rebuild to use this functionality.\n"); - logTerm(); - zmDbClose(); - return -1; -#endif // HAVE_LIBAVCODEC } stream.runStream(); } else if ( source == ZMS_FIFO ) { @@ -320,19 +310,9 @@ int main(int argc, const char *argv[], char **envp) { if ( mode == ZMS_JPEG ) { stream.setStreamType(EventStream::STREAM_JPEG); } else { -#if HAVE_LIBAVCODEC stream.setStreamFormat(format); stream.setStreamBitrate(bitrate); stream.setStreamType(EventStream::STREAM_MPEG); -#else // HAVE_LIBAVCODEC - Error("MPEG streaming of '%s' attempted while disabled", query); - fprintf(stderr, "MPEG streaming is disabled.\n" - "You should ensure the ffmpeg libraries are installed and detected" - " and rebuild to use this functionality.\n"); - logTerm(); - zmDbClose(); - return -1; -#endif // HAVE_LIBAVCODEC } // end if jpeg or mpeg stream.runStream(); } else { diff --git a/zoneminder-config.cmake b/zoneminder-config.cmake index 2457a80ff..ee2912823 100644 --- a/zoneminder-config.cmake +++ b/zoneminder-config.cmake @@ -34,8 +34,6 @@ #cmakedefine HAVE_LIBGNUTLS 1 #cmakedefine HAVE_LIBMYSQLCLIENT 1 #cmakedefine HAVE_MYSQL_H 1 -#cmakedefine HAVE_LIBAVCODEC 1 -#cmakedefine HAVE_LIBAVCODEC_AVCODEC_H 1 #cmakedefine HAVE_LIBAVDEVICE 1 #cmakedefine HAVE_LIBAVDEVICE_AVDEVICE_H 1 #cmakedefine HAVE_LIBAVUTIL_HWCONTEXT_H 1