From 442f1261934dcf4f5f1734e64fcb2e38eb5dd0c6 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 6 May 2021 11:04:38 -0400 Subject: [PATCH] Fix compile on xenial which doesn't have hwaccel --- src/zm_videostore.cpp | 14 ++++++++++++-- src/zm_videostore.h | 5 +++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index 32bf77571..8aad1adb8 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -28,6 +28,7 @@ extern "C" { } VideoStore::CodecData VideoStore::codec_data[] = { +#if HAVE_LIBAVUTIL_HWCONTEXT_H { AV_CODEC_ID_H265, "h265", "hevc_vaapi", AV_PIX_FMT_NV12, AV_PIX_FMT_VAAPI, AV_HWDEVICE_TYPE_VAAPI }, { AV_CODEC_ID_H265, "h265", "hevc_nvenc", AV_PIX_FMT_NV12, AV_PIX_FMT_NV12, AV_HWDEVICE_TYPE_NONE }, { AV_CODEC_ID_H265, "h265", "libx265", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P, AV_HWDEVICE_TYPE_NONE }, @@ -38,6 +39,13 @@ VideoStore::CodecData VideoStore::codec_data[] = { { AV_CODEC_ID_H264, "h264", "h264", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P, AV_HWDEVICE_TYPE_NONE }, { AV_CODEC_ID_H264, "h264", "libx264", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P, AV_HWDEVICE_TYPE_NONE }, { AV_CODEC_ID_MJPEG, "mjpeg", "mjpeg", AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ422P, AV_HWDEVICE_TYPE_NONE }, +#else + { AV_CODEC_ID_H265, "h265", "libx265", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P }, + + { AV_CODEC_ID_H264, "h264", "h264", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P }, + { AV_CODEC_ID_H264, "h264", "libx264", AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P }, + { AV_CODEC_ID_MJPEG, "mjpeg", "mjpeg", AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ422P }, +#endif }; VideoStore::VideoStore( @@ -228,11 +236,10 @@ bool VideoStore::open() { * the motion of the chroma plane does not match the luma plane. */ video_out_ctx->mb_decision = 2; } - +#if HAVE_LIBAVUTIL_HWCONTEXT_H if (codec_data[i].hwdevice_type != AV_HWDEVICE_TYPE_NONE) { ret = av_hwdevice_ctx_create(&hw_device_ctx, codec_data[i].hwdevice_type, - //AV_HWDEVICE_TYPE_VAAPI, NULL, NULL, 0); AVBufferRef *hw_frames_ref; @@ -260,6 +267,7 @@ bool VideoStore::open() { } av_buffer_unref(&hw_frames_ref); } +#endif AVDictionary *opts = 0; std::string Options = monitor->GetEncoderOptions(); @@ -1045,6 +1053,7 @@ int VideoStore::writeVideoFramePacket(ZMPacket *zm_packet) { AVFrame *frame = zm_packet->out_frame; +#if HAVE_LIBAVUTIL_HWCONTEXT_H if (video_out_ctx->hw_frames_ctx) { if (!(hw_frame = av_frame_alloc())) { ret = AVERROR(ENOMEM); @@ -1068,6 +1077,7 @@ int VideoStore::writeVideoFramePacket(ZMPacket *zm_packet) { frame = hw_frame; } // end if hwaccel +#endif //zm_packet->out_frame->coded_picture_number = frame_count; //zm_packet->out_frame->display_picture_number = frame_count; diff --git a/src/zm_videostore.h b/src/zm_videostore.h index 55c71a9aa..47872db2f 100644 --- a/src/zm_videostore.h +++ b/src/zm_videostore.h @@ -15,6 +15,9 @@ extern "C" { #endif #endif #include "libavutil/audio_fifo.h" +#if HAVE_LIBAVUTIL_HWCONTEXT_H + #include "libavutil/hwcontext.h" +#endif } #if HAVE_LIBAVCODEC @@ -32,7 +35,9 @@ class VideoStore { const char *codec_name; const enum AVPixelFormat sw_pix_fmt; const enum AVPixelFormat hw_pix_fmt; +#if HAVE_LIBAVUTIL_HWCONTEXT_H const AVHWDeviceType hwdevice_type; +#endif }; static struct CodecData codec_data[];