diff --git a/scripts/zmx10.pl.in b/scripts/zmx10.pl.in index 17d9546b2..d25e74c8a 100644 --- a/scripts/zmx10.pl.in +++ b/scripts/zmx10.pl.in @@ -191,7 +191,7 @@ sub runServer $dbh = zmDbConnect(); - $x10 = new X10::ActiveHome( port=>ZM_X10_DEVICE, house_code=>ZM_X10_HOUSE_CODE, debug=>0 ); + $x10 = new X10::ActiveHome( port=>$Config{ZM_X10_DEVICE}, house_code=>$Config{ZM_X10_HOUSE_CODE}, debug=>0 ); loadTasks(); @@ -204,7 +204,7 @@ sub runServer #print( "F:".fileno(SERVER)."\n" ); my $reload = undef; my $reload_count = 0; - my $reload_limit = &ZM_X10_DB_RELOAD_INTERVAL / $timeout; + my $reload_limit = $Config{ZM_X10_DB_RELOAD_INTERVAL} / $timeout; while( 1 ) { my $nfound = select( my $rout = $rin, undef, undef, $timeout ); @@ -750,7 +750,7 @@ sub x10listen foreach my $event ( @_ ) { #print( Data::Dumper( $_ )."\n" ); - if ( $event->house_code() eq ZM_X10_HOUSE_CODE ) + if ( $event->house_code() eq $Config{ZM_X10_HOUSE_CODE} ) { my $unit_code = $event->unit_code(); my $device = $device_hash{$unit_code}; diff --git a/src/zm_ffmpeg.cpp b/src/zm_ffmpeg.cpp index 6d08f8576..fbbd23793 100644 --- a/src/zm_ffmpeg.cpp +++ b/src/zm_ffmpeg.cpp @@ -76,13 +76,21 @@ SWScale::SWScale() : gotdefaults(false), swscale_ctx(NULL), input_avframe(NULL), Debug(4,"SWScale object created"); /* Allocate AVFrame for the input */ +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + input_avframe = av_frame_alloc(); +#else input_avframe = avcodec_alloc_frame(); +#endif if(input_avframe == NULL) { Fatal("Failed allocating AVFrame for the input"); } /* Allocate AVFrame for the output */ +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + output_avframe = av_frame_alloc(); +#else output_avframe = avcodec_alloc_frame(); +#endif if(output_avframe == NULL) { Fatal("Failed allocating AVFrame for the output"); } @@ -133,7 +141,7 @@ int SWScale::Convert(const uint8_t* in_buffer, const size_t in_buffer_size, uint return -3; } -#if LIBSWSCALE_VERSION_INT >= AV_VERSION_INT(0, 8, 0) +#if LIBSWSCALE_VERSION_CHECK(0, 8, 0, 8, 0) /* Warn if the input or output pixelformat is not supported */ if(!sws_isSupportedInput(in_pf)) { Warning("swscale does not support the input format: %c%c%c%c",(in_pf)&0xff,((in_pf)&0xff),((in_pf>>16)&0xff),((in_pf>>24)&0xff)); diff --git a/src/zm_ffmpeg.h b/src/zm_ffmpeg.h index 4c824ec84..12415c03c 100644 --- a/src/zm_ffmpeg.h +++ b/src/zm_ffmpeg.h @@ -32,7 +32,17 @@ extern "C" { #include #include #include -#if LIBAVUTIL_VERSION_INT > AV_VERSION_INT(50, 28, 0) + +/* LIBAVUTIL_VERSION_CHECK checks for the right version of libav and FFmpeg + * The original source is vlc (in modules/codec/avcodec/avcommon_compat.h) + * a is the major version + * b and c the minor and micro versions of libav + * d and e the minor and micro versions of FFmpeg */ +#define LIBAVUTIL_VERSION_CHECK(a, b, c, d, e) \ + ( (LIBAVUTIL_VERSION_MICRO < 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(a, b, c) ) || \ + (LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(a, d, e) ) ) + +#if LIBAVUTIL_VERSION_CHECK(50, 29, 0, 29, 0) #include #else #include @@ -42,43 +52,82 @@ extern "C" { #include #include #include -#endif +#endif /* HAVE_LIBAVUTIL_AVUTIL_H */ // AVCODEC #if HAVE_LIBAVCODEC_AVCODEC_H #include + +/* + * LIBAVCODEC_VERSION_CHECK checks for the right version of libav and FFmpeg + * The original source is vlc (in modules/codec/avcodec/avcommon_compat.h) + * a is the major version + * b and c the minor and micro versions of libav + * d and e the minor and micro versions of FFmpeg */ +#define LIBAVCODEC_VERSION_CHECK(a, b, c, d, e) \ + ( (LIBAVCODEC_VERSION_MICRO < 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(a, b, c) ) || \ + (LIBAVCODEC_VERSION_MICRO >= 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(a, d, e) ) ) + #elif HAVE_FFMPEG_AVCODEC_H #include -#endif - +#endif /* HAVE_LIBAVCODEC_AVCODEC_H */ + #if defined(HAVE_LIBAVCODEC_AVCODEC_H) -#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54,25,0) +#if LIBAVCODEC_VERSION_CHECK(54, 25, 0, 51, 100) #define _AVCODECID AVCodecID #else #define _AVCODECID CodecID #endif -#endif +#endif /* HAVE_LIBAVCODEC_AVCODEC_H */ // AVFORMAT #if HAVE_LIBAVFORMAT_AVFORMAT_H #include + +/* LIBAVFORMAT_VERSION_CHECK checks for the right version of libav and FFmpeg + * The original source is vlc (in modules/codec/avcodec/avcommon_compat.h) + * a is the major version + * b and c the minor and micro versions of libav + * d and e the minor and micro versions of FFmpeg */ +#define LIBAVFORMAT_VERSION_CHECK(a, b, c, d, e) \ + ( (LIBAVFORMAT_VERSION_MICRO < 100 && LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(a, b, c) ) || \ + (LIBAVFORMAT_VERSION_MICRO >= 100 && LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(a, d, e) ) ) + #elif HAVE_FFMPEG_AVFORMAT_H #include -#endif +#endif /* HAVE_LIBAVFORMAT_AVFORMAT_H */ // AVDEVICE #if HAVE_LIBAVDEVICE_AVDEVICE_H #include + +/* LIBAVDEVICE_VERSION_CHECK checks for the right version of libav and FFmpeg + * a is the major version + * b and c the minor and micro versions of libav + * d and e the minor and micro versions of FFmpeg */ +#define LIBAVDEVICE_VERSION_CHECK(a, b, c, d, e) \ + ( (LIBAVDEVICE_VERSION_MICRO < 100 && LIBAVDEVICE_VERSION_INT >= AV_VERSION_INT(a, b, c) ) || \ + (LIBAVDEVICE_VERSION_MICRO >= 100 && LIBAVDEVICE_VERSION_INT >= AV_VERSION_INT(a, d, e) ) ) + #elif HAVE_FFMPEG_AVDEVICE_H #include -#endif +#endif /* HAVE_LIBAVDEVICE_AVDEVICE_H */ // SWSCALE #if HAVE_LIBSWSCALE_SWSCALE_H #include + +/* LIBSWSCALE_VERSION_CHECK checks for the right version of libav and FFmpeg + * a is the major version + * b and c the minor and micro versions of libav + * d and e the minor and micro versions of FFmpeg */ +#define LIBSWSCALE_VERSION_CHECK(a, b, c, d, e) \ + ( (LIBSWSCALE_VERSION_MICRO < 100 && LIBSWSCALE_VERSION_INT >= AV_VERSION_INT(a, b, c) ) || \ + (LIBSWSCALE_VERSION_MICRO >= 100 && LIBSWSCALE_VERSION_INT >= AV_VERSION_INT(a, d, e) ) ) + #elif HAVE_FFMPEG_SWSCALE_H #include -#endif +#endif /* HAVE_LIBSWSCALE_SWSCALE_H */ #ifdef __cplusplus } @@ -86,7 +135,7 @@ extern "C" { #if ( HAVE_LIBAVUTIL_AVUTIL_H || HAVE_LIBAVCODEC_AVCODEC_H || HAVE_LIBAVFORMAT_AVFORMAT_H || HAVE_LIBAVDEVICE_AVDEVICE_H ) -#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 4, 0) +#if !LIBAVFORMAT_VERSION_CHECK(52, 107, 0, 107, 0) #if defined(AVIO_WRONLY) #define AVIO_FLAG_WRITE AVIO_WRONLY #else @@ -129,7 +178,7 @@ protected: }; #endif // HAVE_LIBSWSCALE && HAVE_LIBAVUTIL -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54, 25, 0) +#if !LIBAVCODEC_VERSION_CHECK(54, 25, 0, 51, 100) #define AV_CODEC_ID_NONE CODEC_ID_NONE #define AV_CODEC_ID_PCM_MULAW CODEC_ID_PCM_MULAW #define AV_CODEC_ID_PCM_ALAW CODEC_ID_PCM_ALAW @@ -165,18 +214,18 @@ protected: inline static const std::string av_make_error_string(int errnum) { char errbuf[AV_ERROR_MAX_STRING_SIZE]; -#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(50, 12, 13) +#if LIBAVUTIL_VERSION_CHECK(50, 13, 0, 13, 0) av_strerror(errnum, errbuf, AV_ERROR_MAX_STRING_SIZE); #else snprintf(errbuf, AV_ERROR_MAX_STRING_SIZE, "libav error %d", errnum); #endif return (std::string)errbuf; } - + #undef av_err2str #define av_err2str(errnum) av_make_error_string(errnum).c_str() - #endif // __cplusplus + #endif // __cplusplus #endif // ( HAVE_LIBAVUTIL_AVUTIL_H || HAVE_LIBAVCODEC_AVCODEC_H || HAVE_LIBAVFORMAT_AVFORMAT_H || HAVE_LIBAVDEVICE_AVDEVICE_H ) diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 09d39ab53..59f554325 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -170,7 +170,7 @@ int FfmpegCamera::Capture( Image &image ) Debug( 5, "Got packet from stream %d", packet.stream_index ); if ( packet.stream_index == mVideoStreamId ) { -#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 25, 0) +#if LIBAVCODEC_VERSION_CHECK(52, 23, 0, 23, 0) if ( avcodec_decode_video2( mCodecContext, mRawFrame, &frameComplete, &packet ) < 0 ) #else if ( avcodec_decode_video( mCodecContext, mRawFrame, &frameComplete, packet.data, packet.size ) < 0 ) @@ -224,7 +224,7 @@ int FfmpegCamera::OpenFfmpeg() { mIsOpening = true; // Open the input, not necessarily a file -#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 4, 0) +#if !LIBAVFORMAT_VERSION_CHECK(53, 2, 0, 4, 0) Debug ( 1, "Calling av_open_input_file" ); if ( av_open_input_file( &mFormatContext, mPath.c_str(), NULL, 0, NULL ) !=0 ) #else @@ -275,7 +275,7 @@ int FfmpegCamera::OpenFfmpeg() { Debug ( 1, "Opened input" ); // Locate stream info from avformat_open_input -#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 4, 0) +#if !LIBAVFORMAT_VERSION_CHECK(53, 6, 0, 6, 0) Debug ( 1, "Calling av_find_stream_info" ); if ( av_find_stream_info( mFormatContext ) < 0 ) #else @@ -283,14 +283,14 @@ int FfmpegCamera::OpenFfmpeg() { if ( avformat_find_stream_info( mFormatContext, 0 ) < 0 ) #endif Fatal( "Unable to find stream info from %s due to: %s", mPath.c_str(), strerror(errno) ); - + Debug ( 1, "Got stream info" ); // Find first video stream present mVideoStreamId = -1; for (unsigned int i=0; i < mFormatContext->nb_streams; i++ ) { -#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,2,1) +#if (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0)) if ( mFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO ) #else if ( mFormatContext->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO ) @@ -314,7 +314,7 @@ int FfmpegCamera::OpenFfmpeg() { Debug ( 1, "Found decoder" ); // Open the codec -#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 7, 0) +#if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0) Debug ( 1, "Calling avcodec_open" ); if ( avcodec_open( mCodecContext, mCodec ) < 0 ) #else @@ -326,11 +326,19 @@ int FfmpegCamera::OpenFfmpeg() { Debug ( 1, "Opened codec" ); // Allocate space for the native video frame +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + mRawFrame = av_frame_alloc(); +#else mRawFrame = avcodec_alloc_frame(); +#endif // Allocate space for the converted video frame +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + mFrame = av_frame_alloc(); +#else mFrame = avcodec_alloc_frame(); - +#endif + if(mRawFrame == NULL || mFrame == NULL) Fatal( "Unable to allocate frame for %s", mPath.c_str() ); @@ -399,7 +407,7 @@ int FfmpegCamera::CloseFfmpeg(){ } if ( mFormatContext ) { -#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 4, 0) +#if !LIBAVFORMAT_VERSION_CHECK(53, 17, 0, 25, 0) av_close_input_file( mFormatContext ); #else avformat_close_input( &mFormatContext ); diff --git a/src/zm_local_camera.cpp b/src/zm_local_camera.cpp index 6740647bb..e2efa3dfb 100644 --- a/src/zm_local_camera.cpp +++ b/src/zm_local_camera.cpp @@ -434,7 +434,7 @@ LocalCamera::LocalCamera( int p_id, const std::string &p_device, int p_channel, Panic("Unexpected colours: %d",colours); } if( capture ) { -#if LIBSWSCALE_VERSION_INT >= AV_VERSION_INT(0, 8, 0) +#if LIBSWSCALE_VERSION_CHECK(0, 8, 0, 8, 0) if(!sws_isSupportedInput(capturePixFormat)) { Error("swscale does not support the used capture format: %c%c%c%c",(capturePixFormat)&0xff,((capturePixFormat>>8)&0xff),((capturePixFormat>>16)&0xff),((capturePixFormat>>24)&0xff)); conversion_type = 2; /* Try ZM format conversions */ @@ -622,7 +622,11 @@ LocalCamera::LocalCamera( int p_id, const std::string &p_device, int p_channel, #if HAVE_LIBSWSCALE /* Initialize swscale stuff */ if(capture && conversion_type == 1) { +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + tmpPicture = av_frame_alloc(); +#else tmpPicture = avcodec_alloc_frame(); +#endif if ( !tmpPicture ) Fatal( "Could not allocate temporary picture" ); @@ -852,7 +856,11 @@ void LocalCamera::Initialise() Fatal( "Can't map video buffer %d (%d bytes) to memory: %s(%d)", i, vid_buf.length, strerror(errno), errno ); #if HAVE_LIBSWSCALE +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + capturePictures[i] = av_frame_alloc(); +#else capturePictures[i] = avcodec_alloc_frame(); +#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 ); @@ -1006,7 +1014,11 @@ void LocalCamera::Initialise() v4l1_data.buffers[i].height = height; v4l1_data.buffers[i].format = palette; +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + capturePictures[i] = av_frame_alloc(); +#else capturePictures[i] = avcodec_alloc_frame(); +#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 ); diff --git a/src/zm_mpeg.cpp b/src/zm_mpeg.cpp index 90092d96c..eaf0952af 100644 --- a/src/zm_mpeg.cpp +++ b/src/zm_mpeg.cpp @@ -43,12 +43,12 @@ VideoStream::MimeData VideoStream::mime_data[] = { void VideoStream::Initialise( ) { if ( logDebugging() ) - av_log_set_level( AV_LOG_DEBUG ); + av_log_set_level( AV_LOG_DEBUG ); else - av_log_set_level( AV_LOG_QUIET ); - + av_log_set_level( AV_LOG_QUIET ); + av_register_all( ); -#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 13, 0) +#if LIBAVFORMAT_VERSION_CHECK(53, 13, 0, 19, 0) avformat_network_init(); #endif initialised = true; @@ -58,18 +58,18 @@ void VideoStream::SetupFormat( ) { /* allocate the output media context */ ofc = NULL; -#if ((LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 5, 0)) && (LIBAVFORMAT_VERSION_MICRO >= 100)) +#if (LIBAVFORMAT_VERSION_CHECK(53, 2, 0, 2, 0) && (LIBAVFORMAT_VERSION_MICRO >= 100)) avformat_alloc_output_context2( &ofc, NULL, format, filename ); #else AVFormatContext *s= avformat_alloc_context(); - if(!s) + if(!s) { Fatal( "avformat_alloc_context failed %d \"%s\"", (size_t)ofc, av_err2str((size_t)ofc) ); } - + AVOutputFormat *oformat; if (format) { -#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 45, 0) +#if LIBAVFORMAT_VERSION_CHECK(52, 45, 0, 45, 0) oformat = av_guess_format(format, NULL, NULL); #else oformat = guess_format(format, NULL, NULL); @@ -78,7 +78,7 @@ void VideoStream::SetupFormat( ) Fatal( "Requested output format '%s' is not a suitable output format", format ); } } else { -#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 45, 0) +#if LIBAVFORMAT_VERSION_CHECK(52, 45, 0, 45, 0) oformat = av_guess_format(NULL, filename, NULL); #else oformat = guess_format(NULL, filename, NULL); @@ -95,7 +95,7 @@ void VideoStream::SetupFormat( ) { Fatal( "Could not allocate private data for output format." ); } -#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 92, 0) +#if LIBAVFORMAT_VERSION_CHECK(52, 92, 0, 92, 0) if (s->oformat->priv_class) { *(const AVClass**)s->priv_data = s->oformat->priv_class; av_opt_set_defaults(s->priv_data); @@ -186,7 +186,7 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei } else { -#if ((LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 11, 0)) && (LIBAVFORMAT_VERSION_MICRO >= 100)) +#if (LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 11, 0) && (LIBAVFORMAT_VERSION_MICRO >= 100)) Debug( 1, "Could not find codec \"%s\". Using default \"%s\"", codec_name, avcodec_get_name( codec_id ) ); #else Debug( 1, "Could not find codec \"%s\". Using default \"%d\"", codec_name, codec_id ); @@ -202,20 +202,20 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei codec = avcodec_find_encoder( codec_id ); if ( !codec ) { -#if ((LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 11, 0)) && (LIBAVFORMAT_VERSION_MICRO >= 100)) +#if (LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 11, 0) && (LIBAVFORMAT_VERSION_MICRO >= 100)) Fatal( "Could not find encoder for '%s'", avcodec_get_name( codec_id ) ); #else Fatal( "Could not find encoder for '%d'", codec_id ); #endif } -#if ((LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 11, 0)) && (LIBAVFORMAT_VERSION_MICRO >= 100)) +#if (LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 11, 0) && (LIBAVFORMAT_VERSION_MICRO >= 100)) Debug( 1, "Found encoder for '%s'", avcodec_get_name( codec_id ) ); #else Debug( 1, "Found encoder for '%d'", codec_id ); #endif -#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 10, 0) +#if LIBAVFORMAT_VERSION_CHECK(53, 10, 0, 17, 0) ost = avformat_new_stream( ofc, codec ); #else ost = av_new_stream( ofc, 0 ); @@ -311,7 +311,7 @@ void VideoStream::OpenStream( ) AVCodecContext *c = ost->codec; /* open the codec */ -#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 7, 0) +#if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0) if ( (avRet = avcodec_open( c, codec )) < 0 ) #else if ( (avRet = avcodec_open2( c, codec, 0 )) < 0 ) @@ -323,7 +323,11 @@ void VideoStream::OpenStream( ) Debug( 1, "Opened codec" ); /* allocate the encoded raw picture */ +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + opicture = av_frame_alloc( ); +#else opicture = avcodec_alloc_frame( ); +#endif if ( !opicture ) { Panic( "Could not allocate opicture" ); @@ -344,7 +348,11 @@ void VideoStream::OpenStream( ) tmp_opicture = NULL; if ( c->pix_fmt != pf ) { +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + tmp_opicture = av_frame_alloc( ); +#else tmp_opicture = avcodec_alloc_frame( ); +#endif if ( !tmp_opicture ) { Panic( "Could not allocate tmp_opicture" ); @@ -364,9 +372,9 @@ void VideoStream::OpenStream( ) if ( !(of->flags & AVFMT_NOFILE) ) { int ret; -#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 14, 0) +#if LIBAVFORMAT_VERSION_CHECK(53, 15, 0, 21, 0) ret = avio_open2( &ofc->pb, filename, AVIO_FLAG_WRITE, NULL, NULL ); -#elif LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 102, 0) +#elif LIBAVFORMAT_VERSION_CHECK(52, 102, 0, 102, 0) ret = avio_open( &ofc->pb, filename, AVIO_FLAG_WRITE ); #else ret = url_fopen( &ofc->pb, filename, AVIO_FLAG_WRITE ); @@ -395,19 +403,19 @@ void VideoStream::OpenStream( ) Fatal("Unable to malloc memory for outbuf"); } } - -#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 100, 1) + +#if LIBAVFORMAT_VERSION_CHECK(52, 101, 0, 101, 0) av_dump_format(ofc, 0, filename, 1); #else dump_format(ofc, 0, filename, 1); #endif - -#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 4, 0) + +#if !LIBAVFORMAT_VERSION_CHECK(53, 2, 0, 4, 0) int ret = av_write_header( ofc ); #else int ret = avformat_write_header( ofc, NULL ); #endif - + if ( ret < 0 ) { Fatal( "?_write_header failed with error %d \"%s\"", ret, av_err2str( ret ) ); @@ -525,7 +533,7 @@ VideoStream::~VideoStream( ) if ( !(of->flags & AVFMT_NOFILE) ) { /* close the output file */ -#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,2,1) +#if LIBAVFORMAT_VERSION_CHECK(52, 105, 0, 105, 0) avio_close( ofc->pb ); #else url_fclose( ofc->pb ); @@ -625,7 +633,7 @@ double VideoStream::ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size, int got_packet = 0; if ( of->flags & AVFMT_RAWPICTURE ) { -#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51, 2, 1) +#if LIBAVCODEC_VERSION_CHECK(52, 30, 2, 30, 2) pkt->flags |= AV_PKT_FLAG_KEY; #else pkt->flags |= PKT_FLAG_KEY; @@ -640,7 +648,7 @@ double VideoStream::ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size, opicture_ptr->pts = c->frame_number; opicture_ptr->quality = c->global_quality; -#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(54, 0, 0) +#if LIBAVFORMAT_VERSION_CHECK(54, 1, 0, 2, 100) int ret = avcodec_encode_video2( c, pkt, opicture_ptr, &got_packet ); if ( ret != 0 ) { @@ -656,7 +664,7 @@ double VideoStream::ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size, { if ( c->coded_frame->key_frame ) { -#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,2,1) +#if LIBAVCODEC_VERSION_CHECK(52, 30, 2, 30, 2) pkt->flags |= AV_PKT_FLAG_KEY; #else pkt->flags |= PKT_FLAG_KEY; diff --git a/src/zm_remote_camera_rtsp.cpp b/src/zm_remote_camera_rtsp.cpp index 910b2ac42..9f7b39227 100644 --- a/src/zm_remote_camera_rtsp.cpp +++ b/src/zm_remote_camera_rtsp.cpp @@ -162,7 +162,7 @@ int RemoteCameraRtsp::PrimeCapture() mVideoStreamId = -1; for ( unsigned int i = 0; i < mFormatContext->nb_streams; i++ ) -#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,2,1) +#if (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0)) if ( mFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO ) #else if ( mFormatContext->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO ) @@ -183,7 +183,7 @@ int RemoteCameraRtsp::PrimeCapture() Panic( "Unable to locate codec %d decoder", mCodecContext->codec_id ); // Open codec -#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 7, 0) +#if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0) if ( avcodec_open( mCodecContext, mCodec ) < 0 ) #else if ( avcodec_open2( mCodecContext, mCodec, 0 ) < 0 ) @@ -191,11 +191,19 @@ int RemoteCameraRtsp::PrimeCapture() Panic( "Can't open codec" ); // Allocate space for the native video frame +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + mRawFrame = av_frame_alloc(); +#else mRawFrame = avcodec_alloc_frame(); +#endif // Allocate space for the converted video frame +#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101) + mFrame = av_frame_alloc(); +#else mFrame = avcodec_alloc_frame(); - +#endif + if(mRawFrame == NULL || mFrame == NULL) Fatal( "Unable to allocate frame(s)"); @@ -292,7 +300,7 @@ int RemoteCameraRtsp::Capture( Image &image ) { packet.data = buffer.head(); packet.size = buffer.size(); -#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 25, 0) +#if LIBAVCODEC_VERSION_CHECK(52, 23, 0, 23, 0) int len = avcodec_decode_video2( mCodecContext, mRawFrame, &frameComplete, &packet ); #else int len = avcodec_decode_video( mCodecContext, mRawFrame, &frameComplete, packet.data, packet.size ); diff --git a/src/zm_rtsp.cpp b/src/zm_rtsp.cpp index f36814945..02fdc4e22 100644 --- a/src/zm_rtsp.cpp +++ b/src/zm_rtsp.cpp @@ -211,7 +211,7 @@ RtspThread::~RtspThread() { if ( mFormatContext ) { -#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 96, 0) +#if LIBAVFORMAT_VERSION_CHECK(52, 96, 0, 96, 0) avformat_free_context( mFormatContext ); #else av_free_format_context( mFormatContext ); @@ -437,7 +437,7 @@ int RtspThread::run() for ( unsigned int i = 0; i < mFormatContext->nb_streams; i++ ) { SessionDescriptor::MediaDescriptor *mediaDesc = mSessDesc->getStream( i ); -#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,2,1) +#if (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0)) if ( mFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO ) #else if ( mFormatContext->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO ) diff --git a/src/zm_sdp.cpp b/src/zm_sdp.cpp index 361b58850..dbc63a82f 100644 --- a/src/zm_sdp.cpp +++ b/src/zm_sdp.cpp @@ -23,7 +23,7 @@ #include "zm_sdp.h" -#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,2,1) +#if (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0)) SessionDescriptor::StaticPayloadDesc SessionDescriptor::smStaticPayloads[] = { { 0, "PCMU", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_PCM_MULAW, 8000, 1 }, { 3, "GSM", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_NONE, 8000, 1 }, @@ -372,7 +372,7 @@ AVFormatContext *SessionDescriptor::generateFormatContext() const for ( unsigned int i = 0; i < mMediaList.size(); i++ ) { const MediaDescriptor *mediaDesc = mMediaList[i]; -#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 8, 0) +#if !LIBAVFORMAT_VERSION_CHECK(53, 10, 0, 17, 0) AVStream *stream = av_new_stream( formatContext, i ); #else AVStream *stream = avformat_new_stream( formatContext, NULL ); @@ -380,7 +380,7 @@ AVFormatContext *SessionDescriptor::generateFormatContext() const #endif Debug( 1, "Looking for codec for %s payload type %d / %s", mediaDesc->getType().c_str(), mediaDesc->getPayloadType(), mediaDesc->getPayloadDesc().c_str() ); -#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,2,1) +#if (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0)) if ( mediaDesc->getType() == "video" ) stream->codec->codec_type = AVMEDIA_TYPE_VIDEO; else if ( mediaDesc->getType() == "audio" ) @@ -396,6 +396,9 @@ AVFormatContext *SessionDescriptor::generateFormatContext() const stream->codec->codec_type = CODEC_TYPE_DATA; #endif +#if LIBAVCODEC_VERSION_CHECK(55, 50, 3, 60, 103) + std::string codec_name; +#endif if ( mediaDesc->getPayloadType() < PAYLOAD_TYPE_DYNAMIC ) { // Look in static table @@ -404,7 +407,11 @@ AVFormatContext *SessionDescriptor::generateFormatContext() const if ( smStaticPayloads[i].payloadType == mediaDesc->getPayloadType() ) { Debug( 1, "Got static payload type %d, %s", smStaticPayloads[i].payloadType, smStaticPayloads[i].payloadName ); +#if LIBAVCODEC_VERSION_CHECK(55, 50, 3, 60, 103) + codec_name = std::string( smStaticPayloads[i].payloadName ); +#else strncpy( stream->codec->codec_name, smStaticPayloads[i].payloadName, sizeof(stream->codec->codec_name) );; +#endif stream->codec->codec_type = smStaticPayloads[i].codecType; stream->codec->codec_id = smStaticPayloads[i].codecId; stream->codec->sample_rate = smStaticPayloads[i].clockRate; @@ -420,7 +427,11 @@ AVFormatContext *SessionDescriptor::generateFormatContext() const if ( smDynamicPayloads[i].payloadName == mediaDesc->getPayloadDesc() ) { Debug( 1, "Got dynamic payload type %d, %s", mediaDesc->getPayloadType(), smDynamicPayloads[i].payloadName ); +#if LIBAVCODEC_VERSION_CHECK(55, 50, 3, 60, 103) + codec_name = std::string( smStaticPayloads[i].payloadName ); +#else strncpy( stream->codec->codec_name, smDynamicPayloads[i].payloadName, sizeof(stream->codec->codec_name) );; +#endif stream->codec->codec_type = smDynamicPayloads[i].codecType; stream->codec->codec_id = smDynamicPayloads[i].codecId; stream->codec->sample_rate = mediaDesc->getClock(); @@ -428,7 +439,12 @@ AVFormatContext *SessionDescriptor::generateFormatContext() const } } } + +#if LIBAVCODEC_VERSION_CHECK(55, 50, 3, 60, 103) + if ( codec_name.empty() ) +#else if ( !stream->codec->codec_name[0] ) +#endif { Warning( "Can't find payload details for %s payload type %d, name %s", mediaDesc->getType().c_str(), mediaDesc->getPayloadType(), mediaDesc->getPayloadDesc().c_str() ); //return( 0 ); diff --git a/src/zm_sdp.h b/src/zm_sdp.h index b348abc81..0418499e2 100644 --- a/src/zm_sdp.h +++ b/src/zm_sdp.h @@ -38,7 +38,7 @@ protected: { int payloadType; const char payloadName[6]; -#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 64, 0) +#if (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0)) AVMediaType codecType; #else enum CodecType codecType; @@ -51,7 +51,7 @@ protected: struct DynamicPayloadDesc { const char payloadName[32]; -#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 64, 0) +#if (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0)) AVMediaType codecType; #else enum CodecType codecType;