diff --git a/CMakeLists.txt b/CMakeLists.txt index 2940c4a85..616bfd36c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -442,7 +442,8 @@ find_package(FFMPEG REQUIRED COMPONENTS avcodec avformat - avutil) + avutil + swscale) set(CMAKE_REQUIRED_INCLUDES ${FFMPEG_avutil_INCLUDE_DIRS}) check_include_file("libavutil/hwcontext.h" HAVE_LIBAVUTIL_HWCONTEXT_H) @@ -457,16 +458,6 @@ else() set(optlibsnotfound "${optlibsnotfound} AVDevice") endif() -find_package(FFMPEG COMPONENTS swscale) -if(FFMPEG_swscale_FOUND) - set(HAVE_LIBSWSCALE 1) - set(HAVE_LIBSWSCALE_SWSCALE_H 1) - list(APPEND ZM_BIN_LIBS "${FFMPEG_swscale_LIBRARIES}") - set(optlibsfound "${optlibsfound} SWScale") -else() - set(optlibsnotfound "${optlibsnotfound} SWScale") -endif() - find_package(FFMPEG COMPONENTS swresample) if(FFMPEG_swresample_FOUND) set(HAVE_LIBSWRESAMPLE 1) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fe0ee23ee..89eb6924b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -80,6 +80,7 @@ target_link_libraries(zm FFMPEG::avcodec FFMPEG::avformat FFMPEG::avutil + FFMPEG::swscale libbcrypt::bcrypt RtspServer::RtspServer martinmoene::span-lite diff --git a/src/zm_ffmpeg.h b/src/zm_ffmpeg.h index 4d9715420..b0f612285 100644 --- a/src/zm_ffmpeg.h +++ b/src/zm_ffmpeg.h @@ -155,7 +155,6 @@ extern "C" { #endif /* HAVE_LIBAVDEVICE_AVDEVICE_H */ // SWSCALE -#if HAVE_LIBSWSCALE_SWSCALE_H #include /* LIBSWSCALE_VERSION_CHECK checks for the right version of libav and FFmpeg @@ -166,8 +165,6 @@ extern "C" { ( (LIBSWSCALE_VERSION_MICRO < 100 && LIBSWSCALE_VERSION_INT >= AV_VERSION_INT(a, b, c) ) || \ (LIBSWSCALE_VERSION_MICRO >= 100 && LIBSWSCALE_VERSION_INT >= AV_VERSION_INT(a, d, e) ) ) -#endif /* HAVE_LIBSWSCALE_SWSCALE_H */ - #ifdef __cplusplus } #endif diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 87cd080fe..04a39a1b3 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -144,9 +144,7 @@ FfmpegCamera::FfmpegCamera( #endif #endif -#if HAVE_LIBSWSCALE mConvertContext = nullptr; -#endif /* Has to be located inside the constructor so other components such as zma * will receive correct colours and subpixel order */ if ( colours == ZM_COLOUR_RGB32 ) { diff --git a/src/zm_ffmpeg_camera.h b/src/zm_ffmpeg_camera.h index df1cb3936..e320d3b31 100644 --- a/src/zm_ffmpeg_camera.h +++ b/src/zm_ffmpeg_camera.h @@ -62,9 +62,7 @@ class FfmpegCamera : public Camera { int Close() override; bool mCanCapture; -#if HAVE_LIBSWSCALE struct SwsContext *mConvertContext; -#endif int error_count; diff --git a/src/zm_local_camera.cpp b/src/zm_local_camera.cpp index 262ece1e9..4c6bcd97f 100644 --- a/src/zm_local_camera.cpp +++ b/src/zm_local_camera.cpp @@ -45,7 +45,6 @@ static int vidioctl(int fd, int request, void *arg) { return result; } -#if HAVE_LIBSWSCALE static _AVPIXELFORMAT getFfPixFormatFromV4lPalette(int v4l_version, int palette) { _AVPIXELFORMAT pixFormat = AV_PIX_FMT_NONE; @@ -176,7 +175,6 @@ static _AVPIXELFORMAT getFfPixFormatFromV4lPalette(int v4l_version, int palette) return pixFormat; } // end getFfPixFormatFromV4lPalette -#endif // HAVE_LIBSWSCALE static char palette_desc[32]; /* Automatic format selection preferred formats */ @@ -222,9 +220,7 @@ int LocalCamera::vid_fd = -1; int LocalCamera::v4l_version = 0; LocalCamera::V4L2Data LocalCamera::v4l2_data; -#if HAVE_LIBSWSCALE AVFrame **LocalCamera::capturePictures = nullptr; -#endif // HAVE_LIBSWSCALE LocalCamera *LocalCamera::last_camera = nullptr; @@ -326,11 +322,9 @@ LocalCamera::LocalCamera( Warning("Different capture sizes defined for monitors sharing same device, results may be unpredictable or completely wrong"); } -#if HAVE_LIBSWSCALE /* Get ffmpeg pixel format based on capture palette and endianness */ capturePixFormat = getFfPixFormatFromV4lPalette( v4l_version, palette ); imagePixFormat = AV_PIX_FMT_NONE; -#endif // HAVE_LIBSWSCALE } /* V4L2 format matching */ @@ -360,16 +354,11 @@ LocalCamera::LocalCamera( /* Unable to find a solution for the selected palette and target colourspace. Conversion required. Notify the user of performance penalty */ } else { if ( capture ) { -#if HAVE_LIBSWSCALE Info( "No direct match for the selected palette (%d) and target colorspace (%02u). Format conversion is required, performance penalty expected", capturePixFormat, colours); -#else - Info("No direct match for the selected palette and target colorspace. Format conversion is required, performance penalty expected"); -#endif } -#if HAVE_LIBSWSCALE /* Try using swscale for the conversion */ conversion_type = 1; Debug(2, "Using swscale for image conversion"); @@ -397,10 +386,6 @@ LocalCamera::LocalCamera( } #endif } -#else - /* Don't have swscale, see what we can do */ - conversion_type = 2; -#endif /* Our YUYV->Grayscale conversion is a lot faster than swscale's */ if ( colours == ZM_COLOUR_GRAY8 && palette == V4L2_PIX_FMT_YUYV ) { conversion_type = 2; @@ -458,7 +443,6 @@ LocalCamera::LocalCamera( last_camera = this; Debug(3, "Selected subpixelorder: %u", subpixelorder); -#if HAVE_LIBSWSCALE /* Initialize swscale stuff */ if ( capture and (conversion_type == 1) ) { #if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) @@ -490,7 +474,6 @@ LocalCamera::LocalCamera( tmpPicture = nullptr; imgConversionContext = nullptr; } // end if capture and conversion_tye == swscale -#endif if ( capture and device_prime ) Initialise(); } // end LocalCamera::LocalCamera @@ -499,7 +482,6 @@ LocalCamera::~LocalCamera() { if ( device_prime && capture ) Terminate(); -#if HAVE_LIBSWSCALE /* Clean up swscale stuff */ if ( capture && (conversion_type == 1) ) { sws_freeContext(imgConversionContext); @@ -507,8 +489,6 @@ LocalCamera::~LocalCamera() { av_frame_free(&tmpPicture); } -#endif - } // end LocalCamera::~LocalCamera int LocalCamera::Close() { @@ -696,9 +676,8 @@ void LocalCamera::Initialise() { channel_count, v4l_multi_buffer, v4l2_data.reqbufs.count); v4l2_data.buffers = new V4L2MappedBuffer[v4l2_data.reqbufs.count]; -#if HAVE_LIBSWSCALE capturePictures = new AVFrame *[v4l2_data.reqbufs.count]; -#endif // HAVE_LIBSWSCALE + for ( unsigned int i = 0; i < v4l2_data.reqbufs.count; i++ ) { struct v4l2_buffer vid_buf; @@ -720,7 +699,6 @@ void LocalCamera::Initialise() { Fatal("Can't map video buffer %u (%u bytes) to memory: %s(%d)", i, vid_buf.length, strerror(errno), errno); -#if HAVE_LIBSWSCALE #if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) capturePictures[i] = av_frame_alloc(); #else @@ -746,7 +724,6 @@ void LocalCamera::Initialise() { v4l2_data.fmt.fmt.pix.height ); #endif -#endif // HAVE_LIBSWSCALE } // end foreach request buf Debug(3, "Configuring video source"); @@ -792,13 +769,11 @@ void LocalCamera::Terminate() { Debug(3, "Unmapping video buffers"); for ( unsigned int i = 0; i < v4l2_data.reqbufs.count; i++ ) { -#if HAVE_LIBSWSCALE /* Free capture pictures */ #if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) av_frame_free(&capturePictures[i]); #else av_freep(&capturePictures[i]); -#endif #endif if ( munmap(v4l2_data.buffers[i].start, v4l2_data.buffers[i].length) < 0 ) Error("Failed to munmap buffer %d: %s", i, strerror(errno)); @@ -1484,7 +1459,6 @@ int LocalCamera::Capture(std::shared_ptr &zm_packet) { Error("Failed requesting writeable buffer for the captured image."); return -1; } -#if HAVE_LIBSWSCALE if (conversion_type == 1) { Debug(9, "Calling sws_scale to perform the conversion"); /* Use swscale to convert the image directly into the shared memory */ @@ -1505,9 +1479,7 @@ int LocalCamera::Capture(std::shared_ptr &zm_packet) { tmpPicture->data, tmpPicture->linesize ); - } else -#endif - if ( conversion_type == 2 ) { + } else if (conversion_type == 2) { Debug(9, "Calling the conversion function"); /* Call the image conversion function and convert directly into the shared memory */ (*conversion_fptr)(buffer, directbuffer, pixels); @@ -1517,7 +1489,6 @@ int LocalCamera::Capture(std::shared_ptr &zm_packet) { /* JPEG decoding */ zm_packet->image->DecodeJpeg(buffer, buffer_bytesused, colours, subpixelorder); } - } else { Debug(3, "No format conversion performed. Assigning the image"); diff --git a/src/zm_local_camera.h b/src/zm_local_camera.h index 455cd8bc8..f331929d5 100644 --- a/src/zm_local_camera.h +++ b/src/zm_local_camera.h @@ -73,13 +73,11 @@ protected: static V4L2Data v4l2_data; -#if HAVE_LIBSWSCALE static AVFrame **capturePictures; _AVPIXELFORMAT imagePixFormat; _AVPIXELFORMAT capturePixFormat; struct SwsContext *imgConversionContext; AVFrame *tmpPicture; -#endif // HAVE_LIBSWSCALE static LocalCamera *last_camera; diff --git a/src/zm_mpeg.cpp b/src/zm_mpeg.cpp index d73975cc7..d55d39b1d 100644 --- a/src/zm_mpeg.cpp +++ b/src/zm_mpeg.cpp @@ -594,20 +594,14 @@ double VideoStream::EncodeFrame( const uint8_t *buffer, int buffer_size, bool _a double VideoStream::ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size, bool add_timestamp, unsigned int timestamp ) { if ( codec_context->pix_fmt != pf ) { -#ifdef HAVE_LIBSWSCALE static struct SwsContext *img_convert_ctx = nullptr; -#endif // HAVE_LIBSWSCALE memcpy( tmp_opicture->data[0], buffer, buffer_size ); -#ifdef HAVE_LIBSWSCALE if ( !img_convert_ctx ) { img_convert_ctx = sws_getCachedContext( nullptr, codec_context->width, codec_context->height, pf, codec_context->width, codec_context->height, codec_context->pix_fmt, SWS_BICUBIC, nullptr, nullptr, nullptr ); if ( !img_convert_ctx ) Panic( "Unable to initialise image scaling context" ); } sws_scale( img_convert_ctx, tmp_opicture->data, tmp_opicture->linesize, 0, codec_context->height, opicture->data, opicture->linesize ); -#else // HAVE_LIBSWSCALE - Fatal( "swscale is required for MPEG mode" ); -#endif // HAVE_LIBSWSCALE } else { memcpy( opicture->data[0], buffer, buffer_size ); } diff --git a/src/zm_swscale.cpp b/src/zm_swscale.cpp index ff0aec109..6929151d3 100644 --- a/src/zm_swscale.cpp +++ b/src/zm_swscale.cpp @@ -22,7 +22,6 @@ #include "zm_image.h" #include "zm_logger.h" -#if HAVE_LIBSWSCALE SWScale::SWScale() : gotdefaults(false), swscale_ctx(nullptr), input_avframe(nullptr), output_avframe(nullptr) { Debug(4, "SWScale object created"); } @@ -291,4 +290,3 @@ size_t SWScale::GetBufferSize(enum _AVPIXELFORMAT pf, unsigned int width, unsign return outsize = avpicture_get_size(pf, width,height); #endif } -#endif // HAVE_LIBSWSCALE diff --git a/src/zm_swscale.h b/src/zm_swscale.h index 026ecc59e..c0d1e7120 100644 --- a/src/zm_swscale.h +++ b/src/zm_swscale.h @@ -7,7 +7,6 @@ class Image; /* SWScale wrapper class to make our life easier and reduce code reuse */ -#if HAVE_LIBSWSCALE class SWScale { public: SWScale(); @@ -32,6 +31,5 @@ class SWScale { unsigned int default_width; unsigned int default_height; }; -#endif // HAVE_LIBSWSCALE -#endif +#endif // ZM_SWSCALE_H diff --git a/zoneminder-config.cmake b/zoneminder-config.cmake index ee2912823..89add0950 100644 --- a/zoneminder-config.cmake +++ b/zoneminder-config.cmake @@ -37,8 +37,6 @@ #cmakedefine HAVE_LIBAVDEVICE 1 #cmakedefine HAVE_LIBAVDEVICE_AVDEVICE_H 1 #cmakedefine HAVE_LIBAVUTIL_HWCONTEXT_H 1 -#cmakedefine HAVE_LIBSWSCALE 1 -#cmakedefine HAVE_LIBSWSCALE_SWSCALE_H 1 #cmakedefine HAVE_LIBSWRESAMPLE 1 #cmakedefine HAVE_LIBSWRESAMPLE_SWRESAMPLE_H 1 #cmakedefine HAVE_LIBVLC 1