Build: Promote libswresample 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.
This commit is contained in:
Peter Keresztes Schmidt 2021-06-05 14:19:32 +02:00
parent 762476ec76
commit 3d34e6f177
7 changed files with 10 additions and 42 deletions

View File

@ -443,6 +443,7 @@ find_package(FFMPEG REQUIRED
avcodec avcodec
avformat avformat
avutil avutil
swresample
swscale) swscale)
set(CMAKE_REQUIRED_INCLUDES ${FFMPEG_avutil_INCLUDE_DIRS}) set(CMAKE_REQUIRED_INCLUDES ${FFMPEG_avutil_INCLUDE_DIRS})
@ -458,16 +459,6 @@ else()
set(optlibsnotfound "${optlibsnotfound} AVDevice") set(optlibsnotfound "${optlibsnotfound} AVDevice")
endif() endif()
find_package(FFMPEG COMPONENTS swresample)
if(FFMPEG_swresample_FOUND)
set(HAVE_LIBSWRESAMPLE 1)
set(HAVE_LIBSWRESAMPLE_SWRESAMPLE_H 1)
list(APPEND ZM_BIN_LIBS "FFMPEG::swresample")
set(optlibsfound "${optlibsfound} SWResample")
else()
set(optlibsnotfound "${optlibsnotfound} SWResample")
endif()
set(PATH_FFMPEG "") set(PATH_FFMPEG "")
set(OPT_FFMPEG "no") set(OPT_FFMPEG "no")

View File

@ -80,6 +80,7 @@ target_link_libraries(zm
FFMPEG::avcodec FFMPEG::avcodec
FFMPEG::avformat FFMPEG::avformat
FFMPEG::avutil FFMPEG::avutil
FFMPEG::swresample
FFMPEG::swscale FFMPEG::swscale
libbcrypt::bcrypt libbcrypt::bcrypt
RtspServer::RtspServer RtspServer::RtspServer

View File

@ -635,7 +635,6 @@ void zm_packet_copy_rescale_ts(const AVPacket *ipkt, AVPacket *opkt, const AVRat
av_packet_rescale_ts(opkt, src_tb, dst_tb); av_packet_rescale_ts(opkt, src_tb, dst_tb);
} }
#if defined(HAVE_LIBSWRESAMPLE)
int zm_resample_audio(SwrContext *resample_ctx, AVFrame *in_frame, AVFrame *out_frame) { int zm_resample_audio(SwrContext *resample_ctx, AVFrame *in_frame, AVFrame *out_frame) {
if (in_frame) { if (in_frame) {
// Resample the in_frame into the audioSampleBuffer until we process the whole // Resample the in_frame into the audioSampleBuffer until we process the whole
@ -659,7 +658,6 @@ int zm_resample_audio(SwrContext *resample_ctx, AVFrame *in_frame, AVFrame *out_
int zm_resample_get_delay(SwrContext *resample_ctx, int time_base) { int zm_resample_get_delay(SwrContext *resample_ctx, int time_base) {
return swr_get_delay(resample_ctx, time_base); return swr_get_delay(resample_ctx, time_base);
} }
#endif
int zm_add_samples_to_fifo(AVAudioFifo *fifo, AVFrame *frame) { int zm_add_samples_to_fifo(AVAudioFifo *fifo, AVFrame *frame) {
int ret = av_audio_fifo_realloc(fifo, av_audio_fifo_size(fifo) + frame->nb_samples); int ret = av_audio_fifo_realloc(fifo, av_audio_fifo_size(fifo) + frame->nb_samples);

View File

@ -24,21 +24,18 @@
#include "zm_define.h" #include "zm_define.h"
extern "C" { extern "C" {
#include <libswresample/swresample.h>
#ifdef HAVE_LIBSWRESAMPLE
#include "libswresample/swresample.h"
#endif
// AVUTIL // AVUTIL
#include "libavutil/avassert.h" #include <libavutil/avassert.h>
#include <libavutil/avutil.h> #include <libavutil/avutil.h>
#include <libavutil/base64.h> #include <libavutil/base64.h>
#include <libavutil/mathematics.h> #include <libavutil/mathematics.h>
#include <libavutil/avstring.h> #include <libavutil/avstring.h>
#include "libavutil/audio_fifo.h" #include <libavutil/audio_fifo.h>
#include "libavutil/imgutils.h" #include <libavutil/imgutils.h>
#if HAVE_LIBAVUTIL_HWCONTEXT_H #if HAVE_LIBAVUTIL_HWCONTEXT_H
#include "libavutil/hwcontext.h" #include <libavutil/hwcontext.h>
#endif #endif
/* LIBAVUTIL_VERSION_CHECK checks for the right version of libav and FFmpeg /* LIBAVUTIL_VERSION_CHECK checks for the right version of libav and FFmpeg
@ -411,10 +408,8 @@ int zm_send_frame_receive_packet(AVCodecContext *context, AVFrame *frame, AVPack
void zm_packet_copy_rescale_ts(const AVPacket *ipkt, AVPacket *opkt, const AVRational src_tb, const AVRational dst_tb); void zm_packet_copy_rescale_ts(const AVPacket *ipkt, AVPacket *opkt, const AVRational src_tb, const AVRational dst_tb);
#if defined(HAVE_LIBSWRESAMPLE)
int zm_resample_audio(SwrContext *resample_ctx, AVFrame *in_frame, AVFrame *out_frame); int zm_resample_audio(SwrContext *resample_ctx, AVFrame *in_frame, AVFrame *out_frame);
int zm_resample_get_delay(SwrContext *resample_ctx, int time_base); int zm_resample_get_delay(SwrContext *resample_ctx, int time_base);
#endif
int zm_add_samples_to_fifo(AVAudioFifo *fifo, AVFrame *frame); int zm_add_samples_to_fifo(AVAudioFifo *fifo, AVFrame *frame);
int zm_get_samples_from_fifo(AVAudioFifo *fifo, AVFrame *frame); int zm_get_samples_from_fifo(AVAudioFifo *fifo, AVFrame *frame);

View File

@ -87,10 +87,8 @@ VideoStore::VideoStore(
packets_written(0), packets_written(0),
frame_count(0), frame_count(0),
hw_device_ctx(nullptr), hw_device_ctx(nullptr),
#if defined(HAVE_LIBSWRESAMPLE)
resample_ctx(nullptr), resample_ctx(nullptr),
fifo(nullptr), fifo(nullptr),
#endif
converted_in_samples(nullptr), converted_in_samples(nullptr),
filename(filename_in), filename(filename_in),
format(format_in), format(format_in),
@ -722,7 +720,6 @@ VideoStore::~VideoStore() {
#endif #endif
} }
#if defined(HAVE_LIBSWRESAMPLE)
if (resample_ctx) { if (resample_ctx) {
if (fifo) { if (fifo) {
av_audio_fifo_free(fifo); av_audio_fifo_free(fifo);
@ -742,7 +739,6 @@ VideoStore::~VideoStore() {
av_free(converted_in_samples); av_free(converted_in_samples);
converted_in_samples = nullptr; converted_in_samples = nullptr;
} }
#endif
} // end if audio_out_stream } // end if audio_out_stream
Debug(4, "free context"); Debug(4, "free context");
@ -753,10 +749,6 @@ VideoStore::~VideoStore() {
} // VideoStore::~VideoStore() } // VideoStore::~VideoStore()
bool VideoStore::setup_resampler() { bool VideoStore::setup_resampler() {
#if !defined(HAVE_LIBSWRESAMPLE)
Error("Not built with resample library. Cannot do audio conversion to AAC");
return false;
#else
int ret; int ret;
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
@ -925,7 +917,6 @@ bool VideoStore::setup_resampler() {
Error("Could not allocate FIFO"); Error("Could not allocate FIFO");
return false; return false;
} }
#if defined(HAVE_LIBSWRESAMPLE)
resample_ctx = swr_alloc_set_opts(nullptr, resample_ctx = swr_alloc_set_opts(nullptr,
audio_out_ctx->channel_layout, audio_out_ctx->channel_layout,
audio_out_ctx->sample_fmt, audio_out_ctx->sample_fmt,
@ -948,7 +939,6 @@ bool VideoStore::setup_resampler() {
return false; return false;
} }
Debug(1,"Success setting up SWRESAMPLE"); Debug(1,"Success setting up SWRESAMPLE");
#endif
out_frame->nb_samples = audio_out_ctx->frame_size; out_frame->nb_samples = audio_out_ctx->frame_size;
out_frame->format = audio_out_ctx->sample_fmt; out_frame->format = audio_out_ctx->sample_fmt;
@ -984,7 +974,6 @@ bool VideoStore::setup_resampler() {
} }
return true; return true;
#endif
} // end bool VideoStore::setup_resampler() } // end bool VideoStore::setup_resampler()
int VideoStore::writePacket(const std::shared_ptr<ZMPacket> &ipkt) { int VideoStore::writePacket(const std::shared_ptr<ZMPacket> &ipkt) {

View File

@ -9,12 +9,10 @@
#include <memory> #include <memory>
extern "C" { extern "C" {
#ifdef HAVE_LIBSWRESAMPLE #include <libswresample/swresample.h>
#include "libswresample/swresample.h" #include <libavutil/audio_fifo.h>
#endif
#include "libavutil/audio_fifo.h"
#if HAVE_LIBAVUTIL_HWCONTEXT_H #if HAVE_LIBAVUTIL_HWCONTEXT_H
#include "libavutil/hwcontext.h" #include <libavutil/hwcontext.h>
#endif #endif
} }
@ -70,10 +68,8 @@ class VideoStore {
AVBufferRef *hw_device_ctx; AVBufferRef *hw_device_ctx;
#ifdef HAVE_LIBSWRESAMPLE
SwrContext *resample_ctx; SwrContext *resample_ctx;
AVAudioFifo *fifo; AVAudioFifo *fifo;
#endif
uint8_t *converted_in_samples; uint8_t *converted_in_samples;
const char *filename; const char *filename;

View File

@ -37,8 +37,6 @@
#cmakedefine HAVE_LIBAVDEVICE 1 #cmakedefine HAVE_LIBAVDEVICE 1
#cmakedefine HAVE_LIBAVDEVICE_AVDEVICE_H 1 #cmakedefine HAVE_LIBAVDEVICE_AVDEVICE_H 1
#cmakedefine HAVE_LIBAVUTIL_HWCONTEXT_H 1 #cmakedefine HAVE_LIBAVUTIL_HWCONTEXT_H 1
#cmakedefine HAVE_LIBSWRESAMPLE 1
#cmakedefine HAVE_LIBSWRESAMPLE_SWRESAMPLE_H 1
#cmakedefine HAVE_LIBVLC 1 #cmakedefine HAVE_LIBVLC 1
#cmakedefine HAVE_VLC_VLC_H 1 #cmakedefine HAVE_VLC_VLC_H 1
#cmakedefine HAVE_LIBVNC 1 #cmakedefine HAVE_LIBVNC 1