From 2122d6e443bd468972f2def40b4b0450c57130b3 Mon Sep 17 00:00:00 2001 From: SteveGilvarry Date: Thu, 3 Mar 2016 01:03:55 +1100 Subject: [PATCH] Fix all the av_picture related deprecations --- src/zm_ffmpeg.cpp | 41 ++++++++++++++++++++++++++++------- src/zm_ffmpeg.h | 6 +++++ src/zm_ffmpeg_camera.cpp | 14 ++++++++++-- src/zm_local_camera.cpp | 39 +++++++++++++++++++++++++++++---- src/zm_mpeg.cpp | 28 ++++++++++++++++++++++-- src/zm_remote_camera_rtsp.cpp | 16 ++++++++++++-- 6 files changed, 126 insertions(+), 18 deletions(-) diff --git a/src/zm_ffmpeg.cpp b/src/zm_ffmpeg.cpp index 86817c223..1e54ad9e8 100644 --- a/src/zm_ffmpeg.cpp +++ b/src/zm_ffmpeg.cpp @@ -160,12 +160,21 @@ int SWScale::Convert(const uint8_t* in_buffer, const size_t in_buffer_size, uint #endif /* Check the buffer sizes */ - size_t insize = avpicture_get_size(in_pf, width, height); +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + size_t insize = av_image_get_buffer_size(in_pf, width, height,1); +#else + size_t insize = avpicture_get_size(in_pf, width, height); +#endif if(insize != in_buffer_size) { Error("The input buffer size does not match the expected size for the input format. Required: %d Available: %d", insize, in_buffer_size); return -4; } - size_t outsize = avpicture_get_size(out_pf, width, height); +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + size_t outsize = av_image_get_buffer_size(out_pf, width, height,1); +#else + size_t outsize = avpicture_get_size(out_pf, width, height); +#endif + if(outsize < out_buffer_size) { Error("The output buffer is undersized for the output format. Required: %d Available: %d", outsize, out_buffer_size); return -5; @@ -179,13 +188,29 @@ int SWScale::Convert(const uint8_t* in_buffer, const size_t in_buffer_size, uint } /* Fill in the buffers */ - if(!avpicture_fill( (AVPicture*)input_avframe, (uint8_t*)in_buffer, in_pf, width, height ) ) { - Error("Failed filling input frame with input buffer"); - return -7; +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + if(av_image_fill_arrays(input_avframe->data, input_avframe->linesize, + (uint8_t*)in_buffer, in_pf, width, height, 1) <= 0) + { +#else + if(avpicture_fill( (AVPicture*)input_avframe, (uint8_t*)in_buffer, + in_pf, width, height ) <= 0) + { +#endif + Error("Failed filling input frame with input buffer"); + return -7; } - if(!avpicture_fill( (AVPicture*)output_avframe, out_buffer, out_pf, width, height ) ) { - Error("Failed filling output frame with output buffer"); - return -8; +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + if(av_image_fill_arrays(output_avframe->data, output_avframe->linesize, + out_buffer, out_pf, width, height, 1) <= 0) + { +#else + if(avpicture_fill( (AVPicture*)output_avframe, out_buffer, + out_pf, width, height ) <= 0) + { +#endif + Error("Failed filling output frame with output buffer"); + return -8; } /* Do the conversion */ diff --git a/src/zm_ffmpeg.h b/src/zm_ffmpeg.h index 031a10671..7806682c7 100644 --- a/src/zm_ffmpeg.h +++ b/src/zm_ffmpeg.h @@ -47,6 +47,12 @@ extern "C" { #else #include #endif + +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) +#include +#else +#include +#endif #elif HAVE_FFMPEG_AVUTIL_H #include #include diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 062d819d9..cbb3e7eff 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -182,8 +182,13 @@ int FfmpegCamera::Capture( Image &image ) if ( frameComplete ) { Debug( 3, "Got frame %d", frameCount ); - av_image_fill_arrays(mFrame->data, mFrame->linesize, directbuffer, imagePixFormat, width, height, 1); - //avpicture_fill( (AVPicture *)mFrame, directbuffer, imagePixFormat, width, height); +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + av_image_fill_arrays(mFrame->data, mFrame->linesize, + directbuffer, imagePixFormat, width, height, 1); +#else + avpicture_fill( (AVPicture *)mFrame, directbuffer, + imagePixFormat, width, height); +#endif #if HAVE_LIBSWSCALE if(mConvertContext == NULL) { @@ -345,7 +350,12 @@ int FfmpegCamera::OpenFfmpeg() { Debug ( 1, "Allocated frames" ); +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + int pSize = av_image_get_buffer_size( imagePixFormat, width, height,1 ); +#else int pSize = avpicture_get_size( imagePixFormat, width, height ); +#endif + if( (unsigned int)pSize != imagesize) { Fatal("Image size mismatch. Required: %d Available: %d",pSize,imagesize); } diff --git a/src/zm_local_camera.cpp b/src/zm_local_camera.cpp index 022f35dbe..e1dadeb74 100644 --- a/src/zm_local_camera.cpp +++ b/src/zm_local_camera.cpp @@ -626,7 +626,11 @@ LocalCamera::LocalCamera( int p_id, const std::string &p_device, int p_channel, if ( !tmpPicture ) Fatal( "Could not allocate temporary picture" ); - int pSize = avpicture_get_size( imagePixFormat, width, height ); +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + int pSize = av_image_get_buffer_size( imagePixFormat, width, height,1 ); +#else + int pSize = avpicture_get_size( imagePixFormat, width, height ); +#endif if( (unsigned int)pSize != imagesize) { Fatal("Image size mismatch. Required: %d Available: %d",pSize,imagesize); } @@ -859,7 +863,18 @@ void LocalCamera::Initialise() #endif if ( !capturePictures[i] ) Fatal( "Could not allocate picture" ); - avpicture_fill( (AVPicture *)capturePictures[i], (uint8_t*)v4l2_data.buffers[i].start, capturePixFormat, v4l2_data.fmt.fmt.pix.width, v4l2_data.fmt.fmt.pix.height ); +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + av_image_fill_arrays(capturePictures[i]->data, + capturePictures[i]->linesize, + (uint8_t*)v4l2_data.buffers[i].start,capturePixFormat, + v4l2_data.fmt.fmt.pix.width, + v4l2_data.fmt.fmt.pix.height, 1); +#else + avpicture_fill( (AVPicture *)capturePictures[i], + (uint8_t*)v4l2_data.buffers[i].start, capturePixFormat, + v4l2_data.fmt.fmt.pix.width, + v4l2_data.fmt.fmt.pix.height ); +#endif #endif // HAVE_LIBSWSCALE } @@ -1017,7 +1032,16 @@ void LocalCamera::Initialise() #endif if ( !capturePictures[i] ) Fatal( "Could not allocate picture" ); - avpicture_fill( (AVPicture *)capturePictures[i], (unsigned char *)v4l1_data.bufptr+v4l1_data.frames.offsets[i], capturePixFormat, width, height ); +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + av_image_fill_arrays(capturePictures[i]->data, + capturePictures[i]->linesize, + (unsigned char *)v4l1_data.bufptr+v4l1_data.frames.offsets[i], + capturePixFormat, width, height, 1); +#else + avpicture_fill( (AVPicture *)capturePictures[i], + (unsigned char *)v4l1_data.bufptr+v4l1_data.frames.offsets[i], + capturePixFormat, width, height ); +#endif } #endif // HAVE_LIBSWSCALE @@ -2113,7 +2137,14 @@ int LocalCamera::Capture( Image &image ) Debug( 9, "Calling sws_scale to perform the conversion" ); /* Use swscale to convert the image directly into the shared memory */ - avpicture_fill( (AVPicture *)tmpPicture, directbuffer, imagePixFormat, width, height ); +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + av_image_fill_arrays(tmpPicture->data, + tmpPicture->linesize, directbuffer, + imagePixFormat, width, height, 1); +#else + avpicture_fill( (AVPicture *)tmpPicture, directbuffer, + imagePixFormat, width, height ); +#endif sws_scale( imgConversionContext, capturePictures[capture_frame]->data, capturePictures[capture_frame]->linesize, 0, height, tmpPicture->data, tmpPicture->linesize ); } #endif diff --git a/src/zm_mpeg.cpp b/src/zm_mpeg.cpp index 01f9006b8..77a80eb37 100644 --- a/src/zm_mpeg.cpp +++ b/src/zm_mpeg.cpp @@ -333,7 +333,13 @@ void VideoStream::OpenStream( ) Panic( "Could not allocate opicture" ); } +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + int size = av_image_get_buffer_size( c->pix_fmt, c->width, + c->height, 1 ); +#else int size = avpicture_get_size( c->pix_fmt, c->width, c->height ); +#endif + uint8_t *opicture_buf = (uint8_t *)av_malloc( size ); if ( !opicture_buf ) { @@ -344,7 +350,13 @@ void VideoStream::OpenStream( ) #endif Panic( "Could not allocate opicture_buf" ); } - avpicture_fill( (AVPicture *)opicture, opicture_buf, c->pix_fmt, c->width, c->height ); +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + av_image_fill_arrays(opicture->data, opicture->linesize, + opicture_buf, c->pix_fmt, c->width, c->height, 1); +#else + avpicture_fill( (AVPicture *)opicture, opicture_buf, c->pix_fmt, + c->width, c->height ); +#endif /* if the output format is not identical to the input format, then a temporary picture is needed too. It is then converted to the required @@ -361,7 +373,12 @@ void VideoStream::OpenStream( ) { Panic( "Could not allocate tmp_opicture" ); } +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + int size = av_image_get_buffer_size( pf, c->width, + c->height,1 ); +#else int size = avpicture_get_size( pf, c->width, c->height ); +#endif uint8_t *tmp_opicture_buf = (uint8_t *)av_malloc( size ); if ( !tmp_opicture_buf ) { @@ -372,7 +389,14 @@ void VideoStream::OpenStream( ) #endif Panic( "Could not allocate tmp_opicture_buf" ); } - avpicture_fill( (AVPicture *)tmp_opicture, tmp_opicture_buf, pf, c->width, c->height ); +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + av_image_fill_arrays(tmp_opicture->data, + tmp_opicture->linesize, tmp_opicture_buf, pf, + c->width, c->height, 1); +#else + avpicture_fill( (AVPicture *)tmp_opicture, + tmp_opicture_buf, pf, c->width, c->height ); +#endif } } diff --git a/src/zm_remote_camera_rtsp.cpp b/src/zm_remote_camera_rtsp.cpp index a07d97a8e..9bbe458bf 100644 --- a/src/zm_remote_camera_rtsp.cpp +++ b/src/zm_remote_camera_rtsp.cpp @@ -214,7 +214,12 @@ int RemoteCameraRtsp::PrimeCapture() if(mRawFrame == NULL || mFrame == NULL) Fatal( "Unable to allocate frame(s)"); - int pSize = avpicture_get_size( imagePixFormat, width, height ); +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + int pSize = av_image_get_buffer_size( imagePixFormat, width, height, 1 ); +#else + int pSize = avpicture_get_size( imagePixFormat, width, height ); +#endif + if( (unsigned int)pSize != imagesize) { Fatal("Image size mismatch. Required: %d Available: %d",pSize,imagesize); } @@ -330,7 +335,14 @@ int RemoteCameraRtsp::Capture( Image &image ) Debug( 3, "Got frame %d", frameCount ); - avpicture_fill( (AVPicture *)mFrame, directbuffer, imagePixFormat, width, height); +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + av_image_fill_arrays(mFrame->data, mFrame->linesize, + directbuffer, imagePixFormat, width, height, 1); +#else + avpicture_fill( (AVPicture *)mFrame, directbuffer, + imagePixFormat, width, height); +#endif + #if HAVE_LIBSWSCALE if(mConvertContext == NULL) {