From cb7acb36ab08393d1fdcec84fe9d6754c88203ee Mon Sep 17 00:00:00 2001 From: Andy Bauer Date: Sat, 24 Oct 2015 13:04:54 -0500 Subject: [PATCH 1/7] Use relative URL's instead of absolute --- web/index.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/web/index.php b/web/index.php index 70e177aaf..98df13e61 100644 --- a/web/index.php +++ b/web/index.php @@ -58,7 +58,12 @@ else $protocol = 'http'; } define( "ZM_BASE_PROTOCOL", $protocol ); -define( "ZM_BASE_URL", $protocol.'://'.$_SERVER['HTTP_HOST'] ); + +// Absolute URL's are unnecessary and break compatibility with reverse proxies +// define( "ZM_BASE_URL", $protocol.'://'.$_SERVER['HTTP_HOST'] ); + +// Use relative URL's instead +define( "ZM_BASE_URL", "" ); // Check time zone is set if (!ini_get('date.timezone') || !date_default_timezone_set(ini_get('date.timezone'))) { From 0ff7a4e616a56e1cd38e98b8981ccd41d0afca50 Mon Sep 17 00:00:00 2001 From: Dmitry Smirnov Date: Tue, 3 Nov 2015 11:58:23 +1100 Subject: [PATCH 2/7] Replace deprecated FFmpeg API Fixes FTBFS with ffmpeg-2.9; compatible with ffmpeg-2.8. Author: Andreas Cadhalpun Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=803850 --- src/zm_ffmpeg.cpp | 28 +++--- src/zm_ffmpeg.h | 18 ++-- src/zm_ffmpeg_camera.cpp | 12 +-- src/zm_ffmpeg_camera.h | 2 +- src/zm_local_camera.cpp | 182 +++++++++++++++++----------------- src/zm_local_camera.h | 4 +- src/zm_mpeg.cpp | 24 ++--- src/zm_mpeg.h | 2 +- src/zm_remote_camera_rtsp.cpp | 12 +-- src/zm_remote_camera_rtsp.h | 2 +- 10 files changed, 138 insertions(+), 148 deletions(-) diff --git a/src/zm_ffmpeg.cpp b/src/zm_ffmpeg.cpp index fbbd23793..7f262046b 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 PixelFormat GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subpixelorder) { - enum PixelFormat pf; +enum AVPixelFormat GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subpixelorder) { + enum AVPixelFormat pf; Debug(8,"Colours: %d SubpixelOrder: %d",p_colours,p_subpixelorder); @@ -34,10 +34,10 @@ enum PixelFormat GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subpixe { if(p_subpixelorder == ZM_SUBPIX_ORDER_BGR) { /* BGR subpixel order */ - pf = PIX_FMT_BGR24; + pf = AV_PIX_FMT_BGR24; } else { /* Assume RGB subpixel order */ - pf = PIX_FMT_RGB24; + pf = AV_PIX_FMT_RGB24; } break; } @@ -45,25 +45,25 @@ enum PixelFormat GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subpixe { if(p_subpixelorder == ZM_SUBPIX_ORDER_ARGB) { /* ARGB subpixel order */ - pf = PIX_FMT_ARGB; + pf = AV_PIX_FMT_ARGB; } else if(p_subpixelorder == ZM_SUBPIX_ORDER_ABGR) { /* ABGR subpixel order */ - pf = PIX_FMT_ABGR; + pf = AV_PIX_FMT_ABGR; } else if(p_subpixelorder == ZM_SUBPIX_ORDER_BGRA) { /* BGRA subpixel order */ - pf = PIX_FMT_BGRA; + pf = AV_PIX_FMT_BGRA; } else { /* Assume RGBA subpixel order */ - pf = PIX_FMT_RGBA; + pf = AV_PIX_FMT_RGBA; } break; } case ZM_COLOUR_GRAY8: - pf = PIX_FMT_GRAY8; + pf = AV_PIX_FMT_GRAY8; break; default: Panic("Unexpected colours: %d",p_colours); - pf = PIX_FMT_GRAY8; /* Just to shush gcc variable may be unused warning */ + pf = AV_PIX_FMT_GRAY8; /* Just to shush gcc variable may be unused warning */ break; } @@ -99,7 +99,7 @@ SWScale::SWScale() : gotdefaults(false), swscale_ctx(NULL), input_avframe(NULL), SWScale::~SWScale() { /* Free up everything */ - av_free(input_avframe); + av_frame_free(&input_avframe); input_avframe = NULL; av_free(output_avframe); @@ -113,7 +113,7 @@ SWScale::~SWScale() { Debug(4,"SWScale object destroyed"); } -int SWScale::SetDefaults(enum PixelFormat in_pf, enum PixelFormat 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 PixelFormat in_pf, enum PixelFormat out_pf, unsign 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 PixelFormat in_pf, enum PixelFormat 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 PixelFormat in_pf, enum PixelFormat 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 714665cf8..5f23b2b98 100644 --- a/src/zm_ffmpeg.h +++ b/src/zm_ffmpeg.h @@ -143,14 +143,8 @@ extern "C" { #endif #endif -/* Fix for not having SWS_CPU_CAPS_SSE2 defined */ -#ifndef SWS_CPU_CAPS_SSE2 -#define SWS_CPU_CAPS_SSE2 0x02000000 -#endif - - #if HAVE_LIBAVUTIL -enum PixelFormat GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subpixelorder); +enum AVPixelFormat GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subpixelorder); #endif // HAVE_LIBAVUTIL @@ -160,19 +154,19 @@ class SWScale { public: SWScale(); ~SWScale(); - int SetDefaults(enum PixelFormat in_pf, enum PixelFormat 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 PixelFormat in_pf, enum PixelFormat 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 PixelFormat in_pf, enum PixelFormat 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 PixelFormat default_input_pf; - enum PixelFormat 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.cpp b/src/zm_ffmpeg_camera.cpp index 59f554325..1c8de6800 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -62,13 +62,13 @@ FfmpegCamera::FfmpegCamera( int p_id, const std::string &p_path, const std::stri /* 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) { subpixelorder = ZM_SUBPIX_ORDER_RGBA; - imagePixFormat = PIX_FMT_RGBA; + imagePixFormat = AV_PIX_FMT_RGBA; } else if(colours == ZM_COLOUR_RGB24) { subpixelorder = ZM_SUBPIX_ORDER_RGB; - imagePixFormat = PIX_FMT_RGB24; + imagePixFormat = AV_PIX_FMT_RGB24; } else if(colours == ZM_COLOUR_GRAY8) { subpixelorder = ZM_SUBPIX_ORDER_NONE; - imagePixFormat = PIX_FMT_GRAY8; + imagePixFormat = AV_PIX_FMT_GRAY8; } else { Panic("Unexpected colours: %d",colours); } @@ -188,7 +188,7 @@ int FfmpegCamera::Capture( Image &image ) #if HAVE_LIBSWSCALE if(mConvertContext == NULL) { if(config.cpu_extensions && sseversion >= 20) { - mConvertContext = sws_getContext( mCodecContext->width, mCodecContext->height, mCodecContext->pix_fmt, width, height, imagePixFormat, SWS_BICUBIC | SWS_CPU_CAPS_SSE2, NULL, NULL, NULL ); + mConvertContext = sws_getContext( mCodecContext->width, mCodecContext->height, mCodecContext->pix_fmt, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); } else { mConvertContext = sws_getContext( mCodecContext->width, mCodecContext->height, mCodecContext->pix_fmt, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); } @@ -389,8 +389,8 @@ int FfmpegCamera::CloseFfmpeg(){ mCanCapture = false; - av_freep( &mFrame ); - av_freep( &mRawFrame ); + av_frame_free( &mFrame ); + av_frame_free( &mRawFrame ); #if HAVE_LIBSWSCALE if ( mConvertContext ) diff --git a/src/zm_ffmpeg_camera.h b/src/zm_ffmpeg_camera.h index 11b39d3e1..fda88247e 100644 --- a/src/zm_ffmpeg_camera.h +++ b/src/zm_ffmpeg_camera.h @@ -46,7 +46,7 @@ protected: AVCodec *mCodec; AVFrame *mRawFrame; AVFrame *mFrame; - PixelFormat imagePixFormat; + AVPixelFormat imagePixFormat; int OpenFfmpeg(); int ReopenFfmpeg(); diff --git a/src/zm_local_camera.cpp b/src/zm_local_camera.cpp index e2efa3dfb..a631c1825 100644 --- a/src/zm_local_camera.cpp +++ b/src/zm_local_camera.cpp @@ -52,67 +52,67 @@ static int vidioctl( int fd, int request, void *arg ) } #if HAVE_LIBSWSCALE -static PixelFormat getFfPixFormatFromV4lPalette( int v4l_version, int palette ) +static AVPixelFormat getFfPixFormatFromV4lPalette( int v4l_version, int palette ) { - PixelFormat pixFormat = PIX_FMT_NONE; + AVPixelFormat pixFormat = AV_PIX_FMT_NONE; #if ZM_HAS_V4L2 if ( v4l_version == 2 ) { switch( palette ) { -#if defined(V4L2_PIX_FMT_RGB444) && defined(PIX_FMT_RGB444) +#if defined(V4L2_PIX_FMT_RGB444) && defined(AV_PIX_FMT_RGB444) case V4L2_PIX_FMT_RGB444 : - pixFormat = PIX_FMT_RGB444; + pixFormat = AV_PIX_FMT_RGB444; break; #endif // V4L2_PIX_FMT_RGB444 case V4L2_PIX_FMT_RGB555 : - pixFormat = PIX_FMT_RGB555; + pixFormat = AV_PIX_FMT_RGB555; break; case V4L2_PIX_FMT_RGB565 : - pixFormat = PIX_FMT_RGB565; + pixFormat = AV_PIX_FMT_RGB565; break; case V4L2_PIX_FMT_BGR24 : - pixFormat = PIX_FMT_BGR24; + pixFormat = AV_PIX_FMT_BGR24; break; case V4L2_PIX_FMT_RGB24 : - pixFormat = PIX_FMT_RGB24; + pixFormat = AV_PIX_FMT_RGB24; break; case V4L2_PIX_FMT_BGR32 : - pixFormat = PIX_FMT_BGRA; + pixFormat = AV_PIX_FMT_BGRA; break; case V4L2_PIX_FMT_RGB32 : - pixFormat = PIX_FMT_ARGB; + pixFormat = AV_PIX_FMT_ARGB; break; case V4L2_PIX_FMT_GREY : - pixFormat = PIX_FMT_GRAY8; + pixFormat = AV_PIX_FMT_GRAY8; break; case V4L2_PIX_FMT_YUYV : - pixFormat = PIX_FMT_YUYV422; + pixFormat = AV_PIX_FMT_YUYV422; break; case V4L2_PIX_FMT_YUV422P : - pixFormat = PIX_FMT_YUV422P; + pixFormat = AV_PIX_FMT_YUV422P; break; case V4L2_PIX_FMT_YUV411P : - pixFormat = PIX_FMT_YUV411P; + pixFormat = AV_PIX_FMT_YUV411P; break; #ifdef V4L2_PIX_FMT_YUV444 case V4L2_PIX_FMT_YUV444 : - pixFormat = PIX_FMT_YUV444P; + pixFormat = AV_PIX_FMT_YUV444P; break; #endif // V4L2_PIX_FMT_YUV444 case V4L2_PIX_FMT_YUV410 : - pixFormat = PIX_FMT_YUV410P; + pixFormat = AV_PIX_FMT_YUV410P; break; case V4L2_PIX_FMT_YUV420 : - pixFormat = PIX_FMT_YUV420P; + pixFormat = AV_PIX_FMT_YUV420P; break; case V4L2_PIX_FMT_JPEG : case V4L2_PIX_FMT_MJPEG : - pixFormat = PIX_FMT_YUVJ444P; + pixFormat = AV_PIX_FMT_YUVJ444P; break; case V4L2_PIX_FMT_UYVY : - pixFormat = PIX_FMT_UYVY422; + pixFormat = AV_PIX_FMT_UYVY422; break; // These don't seem to have ffmpeg equivalents // See if you can match any of the ones in the default clause below!? @@ -154,32 +154,30 @@ static PixelFormat getFfPixFormatFromV4lPalette( int v4l_version, int palette ) Fatal( "Can't find swscale format for palette %d", palette ); break; // These are all spare and may match some of the above - pixFormat = PIX_FMT_YUVJ420P; - pixFormat = PIX_FMT_YUVJ422P; - pixFormat = PIX_FMT_XVMC_MPEG2_MC; - pixFormat = PIX_FMT_XVMC_MPEG2_IDCT; - pixFormat = PIX_FMT_UYVY422; - pixFormat = PIX_FMT_UYYVYY411; - pixFormat = PIX_FMT_BGR565; - pixFormat = PIX_FMT_BGR555; - pixFormat = PIX_FMT_BGR8; - pixFormat = PIX_FMT_BGR4; - pixFormat = PIX_FMT_BGR4_BYTE; - pixFormat = PIX_FMT_RGB8; - pixFormat = PIX_FMT_RGB4; - pixFormat = PIX_FMT_RGB4_BYTE; - pixFormat = PIX_FMT_NV12; - pixFormat = PIX_FMT_NV21; - pixFormat = PIX_FMT_RGB32_1; - pixFormat = PIX_FMT_BGR32_1; - pixFormat = PIX_FMT_GRAY16BE; - pixFormat = PIX_FMT_GRAY16LE; - pixFormat = PIX_FMT_YUV440P; - pixFormat = PIX_FMT_YUVJ440P; - pixFormat = PIX_FMT_YUVA420P; - //pixFormat = PIX_FMT_VDPAU_H264; - //pixFormat = PIX_FMT_VDPAU_MPEG1; - //pixFormat = PIX_FMT_VDPAU_MPEG2; + pixFormat = AV_PIX_FMT_YUVJ420P; + pixFormat = AV_PIX_FMT_YUVJ422P; + pixFormat = AV_PIX_FMT_UYVY422; + pixFormat = AV_PIX_FMT_UYYVYY411; + pixFormat = AV_PIX_FMT_BGR565; + pixFormat = AV_PIX_FMT_BGR555; + pixFormat = AV_PIX_FMT_BGR8; + pixFormat = AV_PIX_FMT_BGR4; + pixFormat = AV_PIX_FMT_BGR4_BYTE; + pixFormat = AV_PIX_FMT_RGB8; + pixFormat = AV_PIX_FMT_RGB4; + pixFormat = AV_PIX_FMT_RGB4_BYTE; + pixFormat = AV_PIX_FMT_NV12; + pixFormat = AV_PIX_FMT_NV21; + pixFormat = AV_PIX_FMT_RGB32_1; + pixFormat = AV_PIX_FMT_BGR32_1; + pixFormat = AV_PIX_FMT_GRAY16BE; + pixFormat = AV_PIX_FMT_GRAY16LE; + pixFormat = AV_PIX_FMT_YUV440P; + pixFormat = AV_PIX_FMT_YUVJ440P; + pixFormat = AV_PIX_FMT_YUVA420P; + //pixFormat = AV_PIX_FMT_VDPAU_H264; + //pixFormat = AV_PIX_FMT_VDPAU_MPEG1; + //pixFormat = AV_PIX_FMT_VDPAU_MPEG2; } } } @@ -191,67 +189,65 @@ static PixelFormat getFfPixFormatFromV4lPalette( int v4l_version, int palette ) { case VIDEO_PALETTE_RGB32 : if(BigEndian) - pixFormat = PIX_FMT_ARGB; + pixFormat = AV_PIX_FMT_ARGB; else - pixFormat = PIX_FMT_BGRA; + pixFormat = AV_PIX_FMT_BGRA; break; case VIDEO_PALETTE_RGB24 : if(BigEndian) - pixFormat = PIX_FMT_RGB24; + pixFormat = AV_PIX_FMT_RGB24; else - pixFormat = PIX_FMT_BGR24; + pixFormat = AV_PIX_FMT_BGR24; break; case VIDEO_PALETTE_GREY : - pixFormat = PIX_FMT_GRAY8; + pixFormat = AV_PIX_FMT_GRAY8; break; case VIDEO_PALETTE_RGB555 : - pixFormat = PIX_FMT_RGB555; + pixFormat = AV_PIX_FMT_RGB555; break; case VIDEO_PALETTE_RGB565 : - pixFormat = PIX_FMT_RGB565; + pixFormat = AV_PIX_FMT_RGB565; break; case VIDEO_PALETTE_YUYV : case VIDEO_PALETTE_YUV422 : - pixFormat = PIX_FMT_YUYV422; + pixFormat = AV_PIX_FMT_YUYV422; break; case VIDEO_PALETTE_YUV422P : - pixFormat = PIX_FMT_YUV422P; + pixFormat = AV_PIX_FMT_YUV422P; break; case VIDEO_PALETTE_YUV420P : - pixFormat = PIX_FMT_YUV420P; + pixFormat = AV_PIX_FMT_YUV420P; break; default : { Fatal( "Can't find swscale format for palette %d", palette ); break; // These are all spare and may match some of the above - pixFormat = PIX_FMT_YUVJ420P; - pixFormat = PIX_FMT_YUVJ422P; - pixFormat = PIX_FMT_YUVJ444P; - pixFormat = PIX_FMT_XVMC_MPEG2_MC; - pixFormat = PIX_FMT_XVMC_MPEG2_IDCT; - pixFormat = PIX_FMT_UYVY422; - pixFormat = PIX_FMT_UYYVYY411; - pixFormat = PIX_FMT_BGR565; - pixFormat = PIX_FMT_BGR555; - pixFormat = PIX_FMT_BGR8; - pixFormat = PIX_FMT_BGR4; - pixFormat = PIX_FMT_BGR4_BYTE; - pixFormat = PIX_FMT_RGB8; - pixFormat = PIX_FMT_RGB4; - pixFormat = PIX_FMT_RGB4_BYTE; - pixFormat = PIX_FMT_NV12; - pixFormat = PIX_FMT_NV21; - pixFormat = PIX_FMT_RGB32_1; - pixFormat = PIX_FMT_BGR32_1; - pixFormat = PIX_FMT_GRAY16BE; - pixFormat = PIX_FMT_GRAY16LE; - pixFormat = PIX_FMT_YUV440P; - pixFormat = PIX_FMT_YUVJ440P; - pixFormat = PIX_FMT_YUVA420P; - //pixFormat = PIX_FMT_VDPAU_H264; - //pixFormat = PIX_FMT_VDPAU_MPEG1; - //pixFormat = PIX_FMT_VDPAU_MPEG2; + pixFormat = AV_PIX_FMT_YUVJ420P; + pixFormat = AV_PIX_FMT_YUVJ422P; + pixFormat = AV_PIX_FMT_YUVJ444P; + pixFormat = AV_PIX_FMT_UYVY422; + pixFormat = AV_PIX_FMT_UYYVYY411; + pixFormat = AV_PIX_FMT_BGR565; + pixFormat = AV_PIX_FMT_BGR555; + pixFormat = AV_PIX_FMT_BGR8; + pixFormat = AV_PIX_FMT_BGR4; + pixFormat = AV_PIX_FMT_BGR4_BYTE; + pixFormat = AV_PIX_FMT_RGB8; + pixFormat = AV_PIX_FMT_RGB4; + pixFormat = AV_PIX_FMT_RGB4_BYTE; + pixFormat = AV_PIX_FMT_NV12; + pixFormat = AV_PIX_FMT_NV21; + pixFormat = AV_PIX_FMT_RGB32_1; + pixFormat = AV_PIX_FMT_BGR32_1; + pixFormat = AV_PIX_FMT_GRAY16BE; + pixFormat = AV_PIX_FMT_GRAY16LE; + pixFormat = AV_PIX_FMT_YUV440P; + pixFormat = AV_PIX_FMT_YUVJ440P; + pixFormat = AV_PIX_FMT_YUVA420P; + //pixFormat = AV_PIX_FMT_VDPAU_H264; + //pixFormat = AV_PIX_FMT_VDPAU_MPEG1; + //pixFormat = AV_PIX_FMT_VDPAU_MPEG2; } } } @@ -376,7 +372,7 @@ LocalCamera::LocalCamera( int p_id, const std::string &p_device, int p_channel, #if HAVE_LIBSWSCALE /* Get ffmpeg pixel format based on capture palette and endianness */ capturePixFormat = getFfPixFormatFromV4lPalette( v4l_version, palette ); - imagePixFormat = PIX_FMT_NONE; + imagePixFormat = AV_PIX_FMT_NONE; #endif // HAVE_LIBSWSCALE } @@ -423,13 +419,13 @@ LocalCamera::LocalCamera( int p_id, const std::string &p_device, int p_channel, Debug(2,"Using swscale for image conversion"); if(colours == ZM_COLOUR_RGB32) { subpixelorder = ZM_SUBPIX_ORDER_RGBA; - imagePixFormat = PIX_FMT_RGBA; + imagePixFormat = AV_PIX_FMT_RGBA; } else if(colours == ZM_COLOUR_RGB24) { subpixelorder = ZM_SUBPIX_ORDER_RGB; - imagePixFormat = PIX_FMT_RGB24; + imagePixFormat = AV_PIX_FMT_RGB24; } else if(colours == ZM_COLOUR_GRAY8) { subpixelorder = ZM_SUBPIX_ORDER_NONE; - imagePixFormat = PIX_FMT_GRAY8; + imagePixFormat = AV_PIX_FMT_GRAY8; } else { Panic("Unexpected colours: %d",colours); } @@ -541,13 +537,13 @@ LocalCamera::LocalCamera( int p_id, const std::string &p_device, int p_channel, Debug(2,"Using swscale for image conversion"); if(colours == ZM_COLOUR_RGB32) { subpixelorder = ZM_SUBPIX_ORDER_RGBA; - imagePixFormat = PIX_FMT_RGBA; + imagePixFormat = AV_PIX_FMT_RGBA; } else if(colours == ZM_COLOUR_RGB24) { subpixelorder = ZM_SUBPIX_ORDER_RGB; - imagePixFormat = PIX_FMT_RGB24; + imagePixFormat = AV_PIX_FMT_RGB24; } else if(colours == ZM_COLOUR_GRAY8) { subpixelorder = ZM_SUBPIX_ORDER_NONE; - imagePixFormat = PIX_FMT_GRAY8; + imagePixFormat = AV_PIX_FMT_GRAY8; } else { Panic("Unexpected colours: %d",colours); } @@ -636,7 +632,7 @@ LocalCamera::LocalCamera( int p_id, const std::string &p_device, int p_channel, } if(config.cpu_extensions && sseversion >= 20) { - imgConversionContext = sws_getContext(width, height, capturePixFormat, width, height, imagePixFormat, SWS_BICUBIC | SWS_CPU_CAPS_SSE2, NULL, NULL, NULL ); + imgConversionContext = sws_getContext(width, height, capturePixFormat, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); } else { imgConversionContext = sws_getContext(width, height, capturePixFormat, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); } @@ -659,7 +655,7 @@ LocalCamera::~LocalCamera() sws_freeContext(imgConversionContext); imgConversionContext = NULL; - av_free(tmpPicture); + av_frame_free(&tmpPicture); tmpPicture = NULL; } #endif @@ -1089,7 +1085,7 @@ void LocalCamera::Terminate() for ( unsigned int i = 0; i < v4l2_data.reqbufs.count; i++ ) { #if HAVE_LIBSWSCALE /* Free capture pictures */ - av_free(capturePictures[i]); + av_frame_free(&capturePictures[i]); capturePictures[i] = NULL; #endif if ( munmap( v4l2_data.buffers[i].start, v4l2_data.buffers[i].length ) < 0 ) @@ -1107,7 +1103,7 @@ void LocalCamera::Terminate() #if HAVE_LIBSWSCALE for(int i=0; i < v4l1_data.frames.frames; i++) { /* Free capture pictures */ - av_free(capturePictures[i]); + av_frame_free(&capturePictures[i]); capturePictures[i] = NULL; } #endif diff --git a/src/zm_local_camera.h b/src/zm_local_camera.h index 89c6799ca..829e623fb 100644 --- a/src/zm_local_camera.h +++ b/src/zm_local_camera.h @@ -107,8 +107,8 @@ protected: #if HAVE_LIBSWSCALE static AVFrame **capturePictures; - PixelFormat imagePixFormat; - PixelFormat capturePixFormat; + AVPixelFormat imagePixFormat; + AVPixelFormat capturePixFormat; struct SwsContext *imgConversionContext; AVFrame *tmpPicture; #endif // HAVE_LIBSWSCALE diff --git a/src/zm_mpeg.cpp b/src/zm_mpeg.cpp index eaf0952af..0c77dc025 100644 --- a/src/zm_mpeg.cpp +++ b/src/zm_mpeg.cpp @@ -131,10 +131,10 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei { if(subpixelorder == ZM_SUBPIX_ORDER_BGR) { /* BGR subpixel order */ - pf = PIX_FMT_BGR24; + pf = AV_PIX_FMT_BGR24; } else { /* Assume RGB subpixel order */ - pf = PIX_FMT_RGB24; + pf = AV_PIX_FMT_RGB24; } break; } @@ -142,21 +142,21 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei { if(subpixelorder == ZM_SUBPIX_ORDER_ARGB) { /* ARGB subpixel order */ - pf = PIX_FMT_ARGB; + pf = AV_PIX_FMT_ARGB; } else if(subpixelorder == ZM_SUBPIX_ORDER_ABGR) { /* ABGR subpixel order */ - pf = PIX_FMT_ABGR; + pf = AV_PIX_FMT_ABGR; } else if(subpixelorder == ZM_SUBPIX_ORDER_BGRA) { /* BGRA subpixel order */ - pf = PIX_FMT_BGRA; + pf = AV_PIX_FMT_BGRA; } else { /* Assume RGBA subpixel order */ - pf = PIX_FMT_RGBA; + pf = AV_PIX_FMT_RGBA; } break; } case ZM_COLOUR_GRAY8: - pf = PIX_FMT_GRAY8; + pf = AV_PIX_FMT_GRAY8; break; default: Panic("Unexpected colours: %d",colours); @@ -234,7 +234,7 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei c->codec_id = codec->id; c->codec_type = codec->type; - c->pix_fmt = strcmp( "mjpeg", ofc->oformat->name ) == 0 ? PIX_FMT_YUVJ422P : PIX_FMT_YUV420P; + c->pix_fmt = strcmp( "mjpeg", ofc->oformat->name ) == 0 ? AV_PIX_FMT_YUVJ422P : AV_PIX_FMT_YUV420P; if ( bitrate <= 100 ) { // Quality based bitrate control (VBR). Scale is 1..31 where 1 is best. @@ -337,7 +337,7 @@ void VideoStream::OpenStream( ) uint8_t *opicture_buf = (uint8_t *)av_malloc( size ); if ( !opicture_buf ) { - av_free( opicture ); + av_frame_free( &opicture ); Panic( "Could not allocate opicture_buf" ); } avpicture_fill( (AVPicture *)opicture, opicture_buf, c->pix_fmt, c->width, c->height ); @@ -361,7 +361,7 @@ void VideoStream::OpenStream( ) uint8_t *tmp_opicture_buf = (uint8_t *)av_malloc( size ); if ( !tmp_opicture_buf ) { - av_free( tmp_opicture ); + av_frame_free( &tmp_opicture ); Panic( "Could not allocate tmp_opicture_buf" ); } avpicture_fill( (AVPicture *)tmp_opicture, tmp_opicture_buf, pf, c->width, c->height ); @@ -512,11 +512,11 @@ VideoStream::~VideoStream( ) { avcodec_close( ost->codec ); av_free( opicture->data[0] ); - av_free( opicture ); + av_frame_free( &opicture ); if ( tmp_opicture ) { av_free( tmp_opicture->data[0] ); - av_free( tmp_opicture ); + av_frame_free( &tmp_opicture ); } av_free( video_outbuf ); } diff --git a/src/zm_mpeg.h b/src/zm_mpeg.h index 2a09a2942..adfdd57aa 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 PixelFormat pf; + enum AVPixelFormat pf; AVOutputFormat *of; AVFormatContext *ofc; AVStream *ost; diff --git a/src/zm_remote_camera_rtsp.cpp b/src/zm_remote_camera_rtsp.cpp index b7b976996..8b2f79423 100644 --- a/src/zm_remote_camera_rtsp.cpp +++ b/src/zm_remote_camera_rtsp.cpp @@ -63,13 +63,13 @@ RemoteCameraRtsp::RemoteCameraRtsp( int p_id, const std::string &p_method, const /* 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) { subpixelorder = ZM_SUBPIX_ORDER_RGBA; - imagePixFormat = PIX_FMT_RGBA; + imagePixFormat = AV_PIX_FMT_RGBA; } else if(colours == ZM_COLOUR_RGB24) { subpixelorder = ZM_SUBPIX_ORDER_RGB; - imagePixFormat = PIX_FMT_RGB24; + imagePixFormat = AV_PIX_FMT_RGB24; } else if(colours == ZM_COLOUR_GRAY8) { subpixelorder = ZM_SUBPIX_ORDER_NONE; - imagePixFormat = PIX_FMT_GRAY8; + imagePixFormat = AV_PIX_FMT_GRAY8; } else { Panic("Unexpected colours: %d",colours); } @@ -78,8 +78,8 @@ RemoteCameraRtsp::RemoteCameraRtsp( int p_id, const std::string &p_method, const RemoteCameraRtsp::~RemoteCameraRtsp() { - av_freep( &mFrame ); - av_freep( &mRawFrame ); + av_frame_free( &mFrame ); + av_frame_free( &mRawFrame ); #if HAVE_LIBSWSCALE if ( mConvertContext ) @@ -329,7 +329,7 @@ int RemoteCameraRtsp::Capture( Image &image ) #if HAVE_LIBSWSCALE if(mConvertContext == NULL) { if(config.cpu_extensions && sseversion >= 20) { - mConvertContext = sws_getContext( mCodecContext->width, mCodecContext->height, mCodecContext->pix_fmt, width, height, imagePixFormat, SWS_BICUBIC | SWS_CPU_CAPS_SSE2, NULL, NULL, NULL ); + mConvertContext = sws_getContext( mCodecContext->width, mCodecContext->height, mCodecContext->pix_fmt, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); } else { mConvertContext = sws_getContext( mCodecContext->width, mCodecContext->height, mCodecContext->pix_fmt, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); } diff --git a/src/zm_remote_camera_rtsp.h b/src/zm_remote_camera_rtsp.h index 71debf40b..5755e4184 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; - PixelFormat imagePixFormat; + AVPixelFormat imagePixFormat; #endif // HAVE_LIBAVFORMAT #if HAVE_LIBSWSCALE From 97b70b0e28e8bc75970a46a991ddaf098640c1e0 Mon Sep 17 00:00:00 2001 From: SteveGilvarry Date: Tue, 3 Nov 2015 14:57:35 +1100 Subject: [PATCH 3/7] Update Travis to ffmpeg 2.8.1 for testing --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 871891203..d44973e2e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ before_install: - sudo apt-get update -qq - sudo apt-get install -y -qq libpolkit-gobject-1-dev zlib1g-dev apache2 mysql-server php5 php5-mysql build-essential libmysqlclient-dev libssl-dev libbz2-dev libpcre3-dev libdbi-perl libarchive-zip-perl libdate-manip-perl libdevice-serialport-perl libmime-perl libwww-perl libdbd-mysql-perl libsys-mmap-perl yasm automake autoconf cmake libjpeg-turbo8-dev apache2-mpm-prefork libapache2-mod-php5 php5-cli libtheora-dev libvorbis-dev libvpx-dev libx264-dev libvlccore-dev libvlc-dev libvlccore5 libvlc5 2>&1 > /dev/null install: - - git clone -b n2.7.2 --depth=1 git://source.ffmpeg.org/ffmpeg.git + - git clone -b n2.8.1 --depth=1 git://source.ffmpeg.org/ffmpeg.git - cd ffmpeg - ./configure --enable-shared --enable-swscale --enable-gpl --enable-libx264 --enable-libvpx --enable-libvorbis --enable-libtheora - make -j `grep processor /proc/cpuinfo|wc -l` From bc5ef6c5998359d41538d8355c6977ff7d6505bf Mon Sep 17 00:00:00 2001 From: SteveGilvarry Date: Wed, 4 Nov 2015 12:46:26 +1100 Subject: [PATCH 4/7] 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 From 51914994f7fef8916c9fed089bd6bafa76c5a3d5 Mon Sep 17 00:00:00 2001 From: SteveGilvarry Date: Wed, 4 Nov 2015 15:30:14 +1100 Subject: [PATCH 5/7] Migrating from av_free/av_freep to av_frame_free using libavcodec version check. Also replaced recently deprecated av_free_packet with av_packet_unref. --- src/zm_ffmpeg.cpp | 16 ++++++++++++---- src/zm_ffmpeg_camera.cpp | 9 +++++++++ src/zm_local_camera.cpp | 21 +++++++++++++++------ src/zm_mpeg.cpp | 32 ++++++++++++++++++++++++++++---- src/zm_remote_camera_rtsp.cpp | 11 ++++++++++- 5 files changed, 74 insertions(+), 15 deletions(-) diff --git a/src/zm_ffmpeg.cpp b/src/zm_ffmpeg.cpp index f24553416..86817c223 100644 --- a/src/zm_ffmpeg.cpp +++ b/src/zm_ffmpeg.cpp @@ -99,11 +99,19 @@ SWScale::SWScale() : gotdefaults(false), swscale_ctx(NULL), input_avframe(NULL), SWScale::~SWScale() { /* Free up everything */ - av_frame_free(&input_avframe); - input_avframe = NULL; +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + av_frame_free( &input_avframe ); +#else + av_freep( &input_avframe ); +#endif + //input_avframe = NULL; - av_free(output_avframe); - output_avframe = NULL; +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + av_frame_free( &output_avframe ); +#else + av_freep( &output_avframe ); +#endif + //output_avframe = NULL; if(swscale_ctx) { sws_freeContext(swscale_ctx); diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 1c8de6800..ca1d52602 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -205,7 +205,11 @@ int FfmpegCamera::Capture( Image &image ) frameCount++; } } +#if LIBAVCODEC_VERSION_CHECK(57, 8, 0, 12, 100) + av_packet_unref( &packet); +#else av_free_packet( &packet ); +#endif } return (0); } @@ -389,8 +393,13 @@ int FfmpegCamera::CloseFfmpeg(){ mCanCapture = false; +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) av_frame_free( &mFrame ); av_frame_free( &mRawFrame ); +#else + av_freep( &mFrame ); + av_freep( &mRawFrame ); +#endif #if HAVE_LIBSWSCALE if ( mConvertContext ) diff --git a/src/zm_local_camera.cpp b/src/zm_local_camera.cpp index 15d85b6ed..261d4e5f9 100644 --- a/src/zm_local_camera.cpp +++ b/src/zm_local_camera.cpp @@ -655,8 +655,11 @@ LocalCamera::~LocalCamera() sws_freeContext(imgConversionContext); imgConversionContext = NULL; - av_frame_free(&tmpPicture); - tmpPicture = NULL; +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + av_frame_free( &tmpPicture ); +#else + av_freep( &tmpPicture ); +#endif } #endif } @@ -1085,8 +1088,11 @@ void LocalCamera::Terminate() for ( unsigned int i = 0; i < v4l2_data.reqbufs.count; i++ ) { #if HAVE_LIBSWSCALE /* Free capture pictures */ - av_frame_free(&capturePictures[i]); - capturePictures[i] = NULL; +#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) ); @@ -1103,8 +1109,11 @@ void LocalCamera::Terminate() #if HAVE_LIBSWSCALE for(int i=0; i < v4l1_data.frames.frames; i++) { /* Free capture pictures */ - av_frame_free(&capturePictures[i]); - capturePictures[i] = NULL; +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + av_frame_free( &capturePictures[i] ); +#else + av_freep( &capturePictures[i] ); +#endif } #endif diff --git a/src/zm_mpeg.cpp b/src/zm_mpeg.cpp index 0c77dc025..01f9006b8 100644 --- a/src/zm_mpeg.cpp +++ b/src/zm_mpeg.cpp @@ -337,7 +337,11 @@ void VideoStream::OpenStream( ) uint8_t *opicture_buf = (uint8_t *)av_malloc( size ); if ( !opicture_buf ) { - av_frame_free( &opicture ); +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + av_frame_free( &opicture ); +#else + av_freep( &opicture ); +#endif Panic( "Could not allocate opicture_buf" ); } avpicture_fill( (AVPicture *)opicture, opicture_buf, c->pix_fmt, c->width, c->height ); @@ -361,7 +365,11 @@ void VideoStream::OpenStream( ) uint8_t *tmp_opicture_buf = (uint8_t *)av_malloc( size ); if ( !tmp_opicture_buf ) { - av_frame_free( &tmp_opicture ); +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + av_frame_free( &tmp_opicture ); +#else + av_freep( &tmp_opicture ); +#endif Panic( "Could not allocate tmp_opicture_buf" ); } avpicture_fill( (AVPicture *)tmp_opicture, tmp_opicture_buf, pf, c->width, c->height ); @@ -512,11 +520,19 @@ VideoStream::~VideoStream( ) { avcodec_close( ost->codec ); av_free( opicture->data[0] ); +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) av_frame_free( &opicture ); +#else + av_freep( &opicture ); +#endif if ( tmp_opicture ) { av_free( tmp_opicture->data[0] ); +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) av_frame_free( &tmp_opicture ); +#else + av_freep( &tmp_opicture ); +#endif } av_free( video_outbuf ); } @@ -694,7 +710,11 @@ int VideoStream::SendPacket(AVPacket *packet) { { Fatal( "Error %d while writing video frame: %s", ret, av_err2str( errno ) ); } - av_free_packet(packet); +#if LIBAVCODEC_VERSION_CHECK(57, 8, 0, 12, 100) + av_packet_unref( packet ); +#else + av_free_packet( packet ); +#endif return ret; } @@ -735,7 +755,11 @@ void *VideoStream::StreamingThreadCallback(void *ctx){ if (packet->size) { videoStream->SendPacket(packet); } - av_free_packet(packet); +#if LIBAVCODEC_VERSION_CHECK(57, 8, 0, 12, 100) + av_packet_unref( packet); +#else + av_free_packet( packet ); +#endif videoStream->packet_index = videoStream->packet_index ? 0 : 1; // Lock buffer and render next frame. diff --git a/src/zm_remote_camera_rtsp.cpp b/src/zm_remote_camera_rtsp.cpp index 8b2f79423..05e68700a 100644 --- a/src/zm_remote_camera_rtsp.cpp +++ b/src/zm_remote_camera_rtsp.cpp @@ -78,8 +78,13 @@ RemoteCameraRtsp::RemoteCameraRtsp( int p_id, const std::string &p_method, const RemoteCameraRtsp::~RemoteCameraRtsp() { +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) av_frame_free( &mFrame ); av_frame_free( &mRawFrame ); +#else + av_freep( &mFrame ); + av_freep( &mRawFrame ); +#endif #if HAVE_LIBSWSCALE if ( mConvertContext ) @@ -347,7 +352,11 @@ int RemoteCameraRtsp::Capture( Image &image ) } /* frame complete */ - av_free_packet( &packet ); +#if LIBAVCODEC_VERSION_CHECK(57, 8, 0, 12, 100) + av_packet_unref( &packet); +#else + av_free_packet( &packet ); +#endif } /* getFrame() */ if(frameComplete) From 5ba13f1a762054342db060fb2befb932882835cc Mon Sep 17 00:00:00 2001 From: SteveGilvarry Date: Wed, 4 Nov 2015 16:24:39 +1100 Subject: [PATCH 6/7] ffmpeg 2.9 patched removed SSE2 CPU flags as these are automatically detected for all ffmpeg versions circa 2010. This commit removes the if statement on duplicated functions. --- src/zm_ffmpeg_camera.cpp | 7 ++----- src/zm_local_camera.cpp | 9 +++------ src/zm_remote_camera_rtsp.cpp | 7 ++----- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index ca1d52602..9e3a2960c 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -187,11 +187,8 @@ int FfmpegCamera::Capture( Image &image ) #if HAVE_LIBSWSCALE if(mConvertContext == NULL) { - if(config.cpu_extensions && sseversion >= 20) { - mConvertContext = sws_getContext( mCodecContext->width, mCodecContext->height, mCodecContext->pix_fmt, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); - } else { - mConvertContext = sws_getContext( mCodecContext->width, mCodecContext->height, mCodecContext->pix_fmt, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); - } + mConvertContext = sws_getContext( mCodecContext->width, mCodecContext->height, mCodecContext->pix_fmt, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); + if(mConvertContext == NULL) Fatal( "Unable to create conversion context for %s", mPath.c_str() ); } diff --git a/src/zm_local_camera.cpp b/src/zm_local_camera.cpp index 261d4e5f9..022f35dbe 100644 --- a/src/zm_local_camera.cpp +++ b/src/zm_local_camera.cpp @@ -631,14 +631,11 @@ LocalCamera::LocalCamera( int p_id, const std::string &p_device, int p_channel, Fatal("Image size mismatch. Required: %d Available: %d",pSize,imagesize); } - if(config.cpu_extensions && sseversion >= 20) { - imgConversionContext = sws_getContext(width, height, capturePixFormat, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); - } else { - imgConversionContext = sws_getContext(width, height, capturePixFormat, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); - } + imgConversionContext = sws_getContext(width, height, capturePixFormat, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); - if ( !imgConversionContext ) + if ( !imgConversionContext ) { Fatal( "Unable to initialise image scaling context" ); + } } #endif diff --git a/src/zm_remote_camera_rtsp.cpp b/src/zm_remote_camera_rtsp.cpp index 05e68700a..7e00a5d60 100644 --- a/src/zm_remote_camera_rtsp.cpp +++ b/src/zm_remote_camera_rtsp.cpp @@ -333,11 +333,8 @@ int RemoteCameraRtsp::Capture( Image &image ) #if HAVE_LIBSWSCALE if(mConvertContext == NULL) { - if(config.cpu_extensions && sseversion >= 20) { - mConvertContext = sws_getContext( mCodecContext->width, mCodecContext->height, mCodecContext->pix_fmt, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); - } else { - mConvertContext = sws_getContext( mCodecContext->width, mCodecContext->height, mCodecContext->pix_fmt, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); - } + mConvertContext = sws_getContext( mCodecContext->width, mCodecContext->height, mCodecContext->pix_fmt, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); + if(mConvertContext == NULL) Fatal( "Unable to create conversion context"); } From 477e63a87827b8803cbe66211765fd5913b259f6 Mon Sep 17 00:00:00 2001 From: SteveGilvarry Date: Thu, 5 Nov 2015 17:19:58 +1100 Subject: [PATCH 7/7] Reorder RTSPDescribe to avoid -wreorder warnings --- src/zm_remote_camera_rtsp.cpp | 5 +++-- src/zm_rtsp.h | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/zm_remote_camera_rtsp.cpp b/src/zm_remote_camera_rtsp.cpp index 7e00a5d60..a07d97a8e 100644 --- a/src/zm_remote_camera_rtsp.cpp +++ b/src/zm_remote_camera_rtsp.cpp @@ -30,8 +30,9 @@ RemoteCameraRtsp::RemoteCameraRtsp( int p_id, const std::string &p_method, const std::string &p_host, const std::string &p_port, const std::string &p_path, int p_width, int p_height, bool p_rtsp_describe, int p_colours, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture ) : RemoteCamera( p_id, "rtsp", p_host, p_port, p_path, p_width, p_height, p_colours, p_brightness, p_contrast, p_hue, p_colour, p_capture ), - rtspThread( 0 ), - rtsp_describe( p_rtsp_describe ) + rtsp_describe( p_rtsp_describe ), + rtspThread( 0 ) + { if ( p_method == "rtpUni" ) method = RtspThread::RTP_UNICAST; diff --git a/src/zm_rtsp.h b/src/zm_rtsp.h index f5dcb9552..acd28e651 100644 --- a/src/zm_rtsp.h +++ b/src/zm_rtsp.h @@ -50,12 +50,13 @@ private: private: int mId; - bool mRtspDescribe; + RtspMethod mMethod; std::string mProtocol; std::string mHost; std::string mPort; std::string mPath; + bool mRtspDescribe; std::string mUrl; // Reworked authentication system