From bc5ef6c5998359d41538d8355c6977ff7d6505bf Mon Sep 17 00:00:00 2001 From: SteveGilvarry Date: Wed, 4 Nov 2015 12:46:26 +1100 Subject: [PATCH] Handle PixelFormat to AVPixelFormat change using _AVPIXELFORMAT and version check to define correctly. Also at same time define all AV_PIX_FMT_* to PIX_FMT_* --- src/zm_ffmpeg.cpp | 10 +++--- src/zm_ffmpeg.h | 63 +++++++++++++++++++++++++++++++++---- src/zm_ffmpeg_camera.h | 2 +- src/zm_local_camera.cpp | 4 +-- src/zm_local_camera.h | 4 +-- src/zm_mpeg.h | 2 +- src/zm_remote_camera_rtsp.h | 2 +- 7 files changed, 69 insertions(+), 18 deletions(-) diff --git a/src/zm_ffmpeg.cpp b/src/zm_ffmpeg.cpp index 7f262046b..f24553416 100644 --- a/src/zm_ffmpeg.cpp +++ b/src/zm_ffmpeg.cpp @@ -24,8 +24,8 @@ #if HAVE_LIBAVCODEC || HAVE_LIBAVUTIL || HAVE_LIBSWSCALE #if HAVE_LIBAVUTIL -enum AVPixelFormat GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subpixelorder) { - enum AVPixelFormat pf; +enum _AVPIXELFORMAT GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subpixelorder) { + enum _AVPIXELFORMAT pf; Debug(8,"Colours: %d SubpixelOrder: %d",p_colours,p_subpixelorder); @@ -113,7 +113,7 @@ SWScale::~SWScale() { Debug(4,"SWScale object destroyed"); } -int SWScale::SetDefaults(enum AVPixelFormat in_pf, enum AVPixelFormat out_pf, unsigned int width, unsigned int height) { +int SWScale::SetDefaults(enum _AVPIXELFORMAT in_pf, enum _AVPIXELFORMAT out_pf, unsigned int width, unsigned int height) { /* Assign the defaults */ default_input_pf = in_pf; @@ -126,7 +126,7 @@ int SWScale::SetDefaults(enum AVPixelFormat in_pf, enum AVPixelFormat out_pf, un return 0; } -int SWScale::Convert(const uint8_t* in_buffer, const size_t in_buffer_size, uint8_t* out_buffer, const size_t out_buffer_size, enum AVPixelFormat in_pf, enum AVPixelFormat out_pf, unsigned int width, unsigned int height) { +int SWScale::Convert(const uint8_t* in_buffer, const size_t in_buffer_size, uint8_t* out_buffer, const size_t out_buffer_size, enum _AVPIXELFORMAT in_pf, enum _AVPIXELFORMAT out_pf, unsigned int width, unsigned int height) { /* Parameter checking */ if(in_buffer == NULL || out_buffer == NULL) { Error("NULL Input or output buffer"); @@ -189,7 +189,7 @@ int SWScale::Convert(const uint8_t* in_buffer, const size_t in_buffer_size, uint return 0; } -int SWScale::Convert(const Image* img, uint8_t* out_buffer, const size_t out_buffer_size, enum AVPixelFormat in_pf, enum AVPixelFormat out_pf, unsigned int width, unsigned int height) { +int SWScale::Convert(const Image* img, uint8_t* out_buffer, const size_t out_buffer_size, enum _AVPIXELFORMAT in_pf, enum _AVPIXELFORMAT out_pf, unsigned int width, unsigned int height) { if(img->Width() != width) { Error("Source image width differs. Source: %d Output: %d",img->Width(), width); return -12; diff --git a/src/zm_ffmpeg.h b/src/zm_ffmpeg.h index 5f23b2b98..031a10671 100644 --- a/src/zm_ffmpeg.h +++ b/src/zm_ffmpeg.h @@ -53,6 +53,57 @@ extern "C" { #include #include #endif /* HAVE_LIBAVUTIL_AVUTIL_H */ + +#if defined(HAVE_LIBAVUTIL_AVUTIL_H) +#if LIBAVUTIL_VERSION_CHECK(51, 42, 0, 74, 100) + #define _AVPIXELFORMAT AVPixelFormat +#else + #define _AVPIXELFORMAT PixelFormat + #define AV_PIX_FMT_NONE PIX_FMT_NONE + #define AV_PIX_FMT_RGB444 PIX_FMT_RGB444 + #define AV_PIX_FMT_RGB555 PIX_FMT_RGB555 + #define AV_PIX_FMT_RGB565 PIX_FMT_RGB565 + #define AV_PIX_FMT_BGR24 PIX_FMT_BGR24 + #define AV_PIX_FMT_RGB24 PIX_FMT_RGB24 + #define AV_PIX_FMT_BGRA PIX_FMT_BGRA + #define AV_PIX_FMT_ARGB PIX_FMT_ARGB + #define AV_PIX_FMT_ABGR PIX_FMT_ABGR + #define AV_PIX_FMT_RGBA PIX_FMT_RGBA + #define AV_PIX_FMT_GRAY8 PIX_FMT_GRAY8 + #define AV_PIX_FMT_YUYV422 PIX_FMT_YUYV422 + #define AV_PIX_FMT_YUV422P PIX_FMT_YUV422P + #define AV_PIX_FMT_YUV411P PIX_FMT_YUV411P + #define AV_PIX_FMT_YUV444P PIX_FMT_YUV444P + #define AV_PIX_FMT_YUV410P PIX_FMT_YUV410P + #define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P + #define AV_PIX_FMT_YUVJ444P PIX_FMT_YUVJ444P + #define AV_PIX_FMT_UYVY422 PIX_FMT_UYVY422 + #define AV_PIX_FMT_YUVJ420P PIX_FMT_YUVJ420P + #define AV_PIX_FMT_YUVJ422P PIX_FMT_YUVJ422P + #define AV_PIX_FMT_UYVY422 PIX_FMT_UYVY422 + #define AV_PIX_FMT_UYYVYY411 PIX_FMT_UYYVYY411 + #define AV_PIX_FMT_BGR565 PIX_FMT_BGR565 + #define AV_PIX_FMT_BGR555 PIX_FMT_BGR555 + #define AV_PIX_FMT_BGR8 PIX_FMT_BGR8 + #define AV_PIX_FMT_BGR4 PIX_FMT_BGR4 + #define AV_PIX_FMT_BGR4_BYTE PIX_FMT_BGR4_BYTE + #define AV_PIX_FMT_RGB8 PIX_FMT_RGB8 + #define AV_PIX_FMT_RGB4 PIX_FMT_RGB4 + #define AV_PIX_FMT_RGB4_BYTE PIX_FMT_RGB4_BYTE + #define AV_PIX_FMT_NV12 PIX_FMT_NV12 + #define AV_PIX_FMT_NV21 PIX_FMT_NV21 + #define AV_PIX_FMT_RGB32_1 PIX_FMT_RGB32_1 + #define AV_PIX_FMT_BGR32_1 PIX_FMT_BGR32_1 + #define AV_PIX_FMT_GRAY16BE PIX_FMT_GRAY16BE + #define AV_PIX_FMT_GRAY16LE PIX_FMT_GRAY16LE + #define AV_PIX_FMT_YUV440P PIX_FMT_YUV440P + #define AV_PIX_FMT_YUVJ440P PIX_FMT_YUVJ440P + #define AV_PIX_FMT_YUVA420P PIX_FMT_YUVA420P + //#define AV_PIX_FMT_VDPAU_H264 PIX_FMT_VDPAU_H264 + //#define AV_PIX_FMT_VDPAU_MPEG1 PIX_FMT_VDPAU_MPEG1 + //#define AV_PIX_FMT_VDPAU_MPEG2 PIX_FMT_VDPAU_MPEG2 +#endif +#endif /* HAVE_LIBAVUTIL_AVUTIL_H */ // AVCODEC #if HAVE_LIBAVCODEC_AVCODEC_H @@ -144,7 +195,7 @@ extern "C" { #endif #if HAVE_LIBAVUTIL -enum AVPixelFormat GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subpixelorder); +enum _AVPIXELFORMAT GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subpixelorder); #endif // HAVE_LIBAVUTIL @@ -154,19 +205,19 @@ class SWScale { public: SWScale(); ~SWScale(); - int SetDefaults(enum AVPixelFormat in_pf, enum AVPixelFormat out_pf, unsigned int width, unsigned int height); + int SetDefaults(enum _AVPIXELFORMAT in_pf, enum _AVPIXELFORMAT out_pf, unsigned int width, unsigned int height); int ConvertDefaults(const Image* img, uint8_t* out_buffer, const size_t out_buffer_size); int ConvertDefaults(const uint8_t* in_buffer, const size_t in_buffer_size, uint8_t* out_buffer, const size_t out_buffer_size); - int Convert(const Image* img, uint8_t* out_buffer, const size_t out_buffer_size, enum AVPixelFormat in_pf, enum AVPixelFormat out_pf, unsigned int width, unsigned int height); - int Convert(const uint8_t* in_buffer, const size_t in_buffer_size, uint8_t* out_buffer, const size_t out_buffer_size, enum AVPixelFormat in_pf, enum AVPixelFormat out_pf, unsigned int width, unsigned int height); + int Convert(const Image* img, uint8_t* out_buffer, const size_t out_buffer_size, enum _AVPIXELFORMAT in_pf, enum _AVPIXELFORMAT out_pf, unsigned int width, unsigned int height); + int Convert(const uint8_t* in_buffer, const size_t in_buffer_size, uint8_t* out_buffer, const size_t out_buffer_size, enum _AVPIXELFORMAT in_pf, enum _AVPIXELFORMAT out_pf, unsigned int width, unsigned int height); protected: bool gotdefaults; struct SwsContext* swscale_ctx; AVFrame* input_avframe; AVFrame* output_avframe; - enum AVPixelFormat default_input_pf; - enum AVPixelFormat default_output_pf; + enum _AVPIXELFORMAT default_input_pf; + enum _AVPIXELFORMAT default_output_pf; unsigned int default_width; unsigned int default_height; }; diff --git a/src/zm_ffmpeg_camera.h b/src/zm_ffmpeg_camera.h index fda88247e..ff3ee5d1d 100644 --- a/src/zm_ffmpeg_camera.h +++ b/src/zm_ffmpeg_camera.h @@ -46,7 +46,7 @@ protected: AVCodec *mCodec; AVFrame *mRawFrame; AVFrame *mFrame; - AVPixelFormat imagePixFormat; + _AVPIXELFORMAT imagePixFormat; int OpenFfmpeg(); int ReopenFfmpeg(); diff --git a/src/zm_local_camera.cpp b/src/zm_local_camera.cpp index a631c1825..15d85b6ed 100644 --- a/src/zm_local_camera.cpp +++ b/src/zm_local_camera.cpp @@ -52,9 +52,9 @@ static int vidioctl( int fd, int request, void *arg ) } #if HAVE_LIBSWSCALE -static AVPixelFormat getFfPixFormatFromV4lPalette( int v4l_version, int palette ) +static _AVPIXELFORMAT getFfPixFormatFromV4lPalette( int v4l_version, int palette ) { - AVPixelFormat pixFormat = AV_PIX_FMT_NONE; + _AVPIXELFORMAT pixFormat = AV_PIX_FMT_NONE; #if ZM_HAS_V4L2 if ( v4l_version == 2 ) diff --git a/src/zm_local_camera.h b/src/zm_local_camera.h index 829e623fb..016e80150 100644 --- a/src/zm_local_camera.h +++ b/src/zm_local_camera.h @@ -107,8 +107,8 @@ protected: #if HAVE_LIBSWSCALE static AVFrame **capturePictures; - AVPixelFormat imagePixFormat; - AVPixelFormat capturePixFormat; + _AVPIXELFORMAT imagePixFormat; + _AVPIXELFORMAT capturePixFormat; struct SwsContext *imgConversionContext; AVFrame *tmpPicture; #endif // HAVE_LIBSWSCALE diff --git a/src/zm_mpeg.h b/src/zm_mpeg.h index adfdd57aa..b54776e70 100644 --- a/src/zm_mpeg.h +++ b/src/zm_mpeg.h @@ -42,7 +42,7 @@ protected: const char *filename; const char *format; const char *codec_name; - enum AVPixelFormat pf; + enum _AVPIXELFORMAT pf; AVOutputFormat *of; AVFormatContext *ofc; AVStream *ost; diff --git a/src/zm_remote_camera_rtsp.h b/src/zm_remote_camera_rtsp.h index 5755e4184..420ac9cb2 100644 --- a/src/zm_remote_camera_rtsp.h +++ b/src/zm_remote_camera_rtsp.h @@ -59,7 +59,7 @@ protected: AVCodec *mCodec; AVFrame *mRawFrame; AVFrame *mFrame; - AVPixelFormat imagePixFormat; + _AVPIXELFORMAT imagePixFormat; #endif // HAVE_LIBAVFORMAT #if HAVE_LIBSWSCALE