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.pull/3278/head
parent
7d15396833
commit
a9ad5c5eee
|
@ -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)
|
||||
|
|
|
@ -77,6 +77,7 @@ target_include_directories(zm
|
|||
|
||||
target_link_libraries(zm
|
||||
PUBLIC
|
||||
FFMPEG::avcodec
|
||||
FFMPEG::avformat
|
||||
FFMPEG::avutil
|
||||
libbcrypt::bcrypt
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -110,7 +110,6 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
// AVCODEC
|
||||
#if HAVE_LIBAVCODEC_AVCODEC_H
|
||||
#include <libavcodec/avcodec.h>
|
||||
|
||||
/*
|
||||
|
@ -128,7 +127,6 @@ extern "C" {
|
|||
#else
|
||||
#define _AVCODECID CodecID
|
||||
#endif
|
||||
#endif /* HAVE_LIBAVCODEC_AVCODEC_H */
|
||||
|
||||
// AVFORMAT
|
||||
#include <libavformat/avformat.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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
|
||||
#if HAVE_LIBAVCODEC
|
||||
extern "C" {
|
||||
#include <libavutil/mathematics.h>
|
||||
#include <libavcodec/avcodec.h>
|
||||
|
@ -766,5 +765,3 @@ void *VideoStream::StreamingThreadCallback(void *ctx){
|
|||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#endif // HAVE_LIBAVCODEC
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
#include "zm_ffmpeg.h"
|
||||
#include <pthread.h>
|
||||
|
||||
#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
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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
|
||||
|
|
|
@ -29,8 +29,6 @@
|
|||
#include <string>
|
||||
#include <sys/time.h>
|
||||
|
||||
#if HAVE_LIBAVCODEC
|
||||
|
||||
struct RtpDataHeader;
|
||||
|
||||
class RtpSource
|
||||
|
@ -193,6 +191,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
#endif // HAVE_LIBAVCODEC
|
||||
|
||||
#endif // ZM_RTP_SOURCE_H
|
||||
|
|
|
@ -28,12 +28,10 @@
|
|||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -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 } };
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
20
src/zms.cpp
20
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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue