diff --git a/src/event.cpp b/src/event.cpp index d84de730..a74b288b 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -135,15 +135,13 @@ static void event_vlp_putpipem(ctx_dev *cam) static void event_image_detect(ctx_dev *cam) { char filename[PATH_MAX]; - int passthrough; if (cam->new_img & NEWIMG_ON) { mypicname(cam, filename,"%s/%s.%s" , cam->conf->picture_filename , cam->conf->picture_type); - passthrough = mycheck_passthrough(cam); cam->filetype = FTYPE_IMAGE; - if ((cam->imgs.size_high > 0) && (passthrough == false)) { + if ((cam->imgs.size_high > 0) && (cam->movie_passthrough == false)) { cam->picture->save_norm(filename, cam->current_image->image_high); } else { cam->picture->save_norm(filename,cam->current_image->image_norm); @@ -181,7 +179,7 @@ static void event_image_snapshot(ctx_dev *cam) { char filename[PATH_MAX]; char linkpath[PATH_MAX]; - int offset, passthrough; + int offset; offset = (int)cam->conf->snapshot_filename.length() - 8; if (offset < 0) { @@ -192,9 +190,8 @@ static void event_image_snapshot(ctx_dev *cam) mypicname(cam, filename,"%s/%s.%s" , cam->conf->snapshot_filename , cam->conf->picture_type); - passthrough = mycheck_passthrough(cam); cam->filetype = FTYPE_IMAGE_SNAPSHOT; - if ((cam->imgs.size_high > 0) && (passthrough == false)) { + if ((cam->imgs.size_high > 0) && (cam->movie_passthrough == false)) { cam->picture->save_norm(filename, cam->current_image->image_high); } else { cam->picture->save_norm(filename, cam->current_image->image_norm); @@ -217,9 +214,8 @@ static void event_image_snapshot(ctx_dev *cam) , cam->conf->snapshot_filename , cam->conf->picture_type); remove(filename); - passthrough = mycheck_passthrough(cam); cam->filetype = FTYPE_IMAGE_SNAPSHOT; - if ((cam->imgs.size_high > 0) && (!passthrough)) { + if ((cam->imgs.size_high > 0) && (cam->movie_passthrough == false)) { cam->picture->save_norm(filename, cam->current_image->image_high); } else { cam->picture->save_norm(filename, cam->current_image->image_norm); @@ -235,7 +231,6 @@ static void event_image_preview(ctx_dev *cam) { char filename[PATH_MAX]; ctx_image_data *saved_current_image; - int passthrough; if (cam->imgs.image_preview.diffs) { saved_current_image = cam->current_image; @@ -248,9 +243,8 @@ static void event_image_preview(ctx_dev *cam) , cam->conf->picture_filename , cam->conf->picture_type); - passthrough = mycheck_passthrough(cam); cam->filetype = FTYPE_IMAGE; - if ((cam->imgs.size_high > 0) && (passthrough == false)) { + if ((cam->imgs.size_high > 0) && (cam->movie_passthrough == false)) { cam->picture->save_norm(filename, cam->imgs.image_preview.image_high); } else { cam->picture->save_norm(filename, cam->imgs.image_preview.image_norm); diff --git a/src/movie.cpp b/src/movie.cpp index 50ca3a8a..6a2bfa70 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -19,18 +19,6 @@ /* * The contents of this file has been derived from the output_example.c * and apiexample.c from the FFmpeg distribution. - * - * This file has been modified so that only major versions greater than - * 53 are supported. - * Note that while the conditions are based upon LIBAVFORMAT, not all of the changes are - * specific to libavformat.h. Some changes could be related to other components of ffmpeg. - * This is for simplicity. The avformat version has historically changed at the same time - * as the other components so it is easier to have a single version number to track rather - * than the particular version numbers which are associated with each component. - * The libav variant also has different apis with the same major/minor version numbers. - * As such, it is occasionally necessary to look at the microversion number. Numbers - * greater than 100 for micro version indicate ffmpeg whereas numbers less than 100 - * indicate libav */ #include "motionplus.hpp" @@ -43,7 +31,7 @@ static void movie_free_pkt(ctx_movie *movie) { - mypacket_free(movie->pkt); + av_packet_free(&movie->pkt); movie->pkt = NULL; } @@ -108,12 +96,12 @@ static void movie_free_context(ctx_movie *movie) { if (movie->picture != NULL) { - myframe_free(movie->picture); + av_frame_free(&movie->picture); movie->picture = NULL; } if (movie->ctx_codec != NULL) { - myavcodec_close(movie->ctx_codec); + avcodec_free_context(&movie->ctx_codec); movie->ctx_codec = NULL; } @@ -232,9 +220,6 @@ static int movie_get_oformat(ctx_movie *movie) static int movie_encode_video(ctx_movie *movie) { - - #if (MYFFVER >= 57041) - //ffmpeg version 3.1 and after int retcd = 0; char errstr[128]; @@ -264,76 +249,6 @@ static int movie_encode_video(ctx_movie *movie) } return 0; - - #elif (MYFFVER > 54006) - - int retcd = 0; - char errstr[128]; - int got_packet_ptr; - - retcd = avcodec_encode_video2(movie->ctx_codec, movie->pkt, movie->picture, &got_packet_ptr); - if (retcd < 0 ) { - av_strerror(retcd, errstr, sizeof(errstr)); - MOTPLS_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Error encoding video:%s"),errstr); - //Packet is freed upon failure of encoding - return -1; - } - if (got_packet_ptr == 0) { - //Buffered packet. Throw special return code - movie_free_pkt(movie); - return -2; - } - - /* This kills compiler warnings. Nal setting is only for recent movie versions*/ - if (movie->preferred_codec == USER_CODEC_V4L2M2M) { - movie_encode_nal(movie); - } - - return 0; - - #else - - int retcd = 0; - uint8_t *video_outbuf; - int video_outbuf_size; - - video_outbuf_size = (movie->ctx_codec->width +16) * (movie->ctx_codec->height +16) * 1; - video_outbuf =(uint8_t *) mymalloc(video_outbuf_size); - - retcd = avcodec_encode_video(movie->strm_video->codec, video_outbuf, video_outbuf_size, movie->picture); - if (retcd < 0 ) { - MOTPLS_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Error encoding video")); - movie_free_pkt(movie); - return -1; - } - if (retcd == 0 ) { - // No bytes encoded => buffered=>special handling - movie_free_pkt(movie); - return -2; - } - - // Encoder did not provide metadata, set it up manually - movie->pkt->size = retcd; - movie->pkt->data = video_outbuf; - - if (movie->picture->key_frame == 1) { - movie->pkt->flags |= AV_PKT_FLAG_KEY; - } - - movie->pkt->pts = movie->picture->pts; - movie->pkt->dts = movie->pkt->pts; - - myfree(&video_outbuf); - - /* This kills compiler warnings. Nal setting is only for recent movie versions*/ - if (movie->preferred_codec == USER_CODEC_V4L2M2M) { - movie_encode_nal(movie); - } - - return 0; - - #endif - } static int movie_set_pts(ctx_movie *movie, const struct timespec *ts1) @@ -481,7 +396,6 @@ static int movie_set_codec(ctx_movie *movie) return retcd; } - #if (MYFFVER >= 57041) movie->strm_video = avformat_new_stream(movie->oc, movie->codec); if (!movie->strm_video) { MOTPLS_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not alloc stream")); @@ -494,16 +408,6 @@ static int movie_set_codec(ctx_movie *movie) movie_free_context(movie); return -1; } - #else - movie->strm_video = avformat_new_stream(movie->oc, movie->codec); - if (!movie->strm_video) { - MOTPLS_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not alloc stream")); - movie_free_context(movie); - return -1; - } - movie->ctx_codec = movie->strm_video->codec; - #endif - if (movie->tlapse != TIMELAPSE_NONE) { movie->ctx_codec->gop_size = 1; @@ -584,8 +488,6 @@ static int movie_set_codec(ctx_movie *movie) static int movie_set_stream(ctx_movie *movie) { - - #if (MYFFVER >= 57041) int retcd; char errstr[128]; @@ -597,7 +499,6 @@ static int movie_set_stream(ctx_movie *movie) movie_free_context(movie); return -1; } - #endif movie->strm_video->time_base = av_make_q(1, movie->fps); @@ -679,7 +580,7 @@ static int movie_set_picture(ctx_movie *movie) int retcd; char errstr[128]; - movie->picture = myframe_alloc(); + movie->picture = av_frame_alloc(); if (!movie->picture) { MOTPLS_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("could not alloc frame")); movie_free_context(movie); @@ -733,15 +634,6 @@ static int movie_set_outputfile(ctx_movie *movie) int retcd; char errstr[128]; - #if (MYFFVER < 58000) - retcd = snprintf(movie->oc->full_nm, sizeof(movie->oc->full_nm), "%s", movie->full_nm); - if ((retcd < 0) || (retcd >= PATH_MAX)) { - MOTPLS_LOG(ERR, TYPE_ENCODER, NO_ERRNO - ,_("Error setting file name")); - return -1; - } - #endif - /* Open the output file, if needed. */ if ((movie_timelapse_exists(movie->full_nm) == 0) || (movie->tlapse != TIMELAPSE_APPEND)) { clock_gettime(CLOCK_MONOTONIC, &movie->cb_st_ts); @@ -807,9 +699,6 @@ static int movie_set_outputfile(ctx_movie *movie) static int movie_flush_codec(ctx_movie *movie) { - #if (MYFFVER >= 57041) - //ffmpeg version 3.1 and after - int retcd; int recv_cd = 0; char errstr[128]; @@ -856,11 +745,6 @@ static int movie_flush_codec(ctx_movie *movie) } } return 0; - #else - (void)movie; - return 0; - #endif - } static int movie_put_frame(ctx_movie *movie, const struct timespec *ts1) @@ -975,7 +859,7 @@ static void movie_passthru_write(ctx_movie *movie, int indx) movie->pkt = mypacket_alloc(movie->pkt); movie->netcam_data->pktarray[indx].iswritten = true; - retcd = mycopy_packet(movie->pkt, movie->netcam_data->pktarray[indx].packet); + retcd = av_packet_ref(movie->pkt, movie->netcam_data->pktarray[indx].packet); if (retcd < 0) { av_strerror(retcd, errstr, sizeof(errstr)); MOTPLS_LOG(INF, TYPE_ENCODER, NO_ERRNO, "av_copy_packet: %s",errstr); @@ -1198,7 +1082,6 @@ static int movie_passthru_streams_audio(ctx_movie *movie, AVStream *stream_in) static int movie_passthru_streams(ctx_movie *movie) { - #if (MYFFVER >= 57041) int retcd, indx; AVStream *stream_in; @@ -1222,11 +1105,6 @@ static int movie_passthru_streams(ctx_movie *movie) pthread_mutex_unlock(&movie->netcam_data->mutex_transfer); return 0; - #else - /* This is disabled in the check_passthrough but we need it here for compiling */ - MOTPLS_LOG(INF, TYPE_ENCODER, NO_ERRNO, _("Pass-through disabled. ffmpeg too old")); - return -1; - #endif } static int movie_passthru_check(ctx_movie *movie) @@ -1804,12 +1682,11 @@ int movie_init_extpipe(ctx_dev *cam) int movie_put_extpipe(ctx_dev *cam) { - int passthrough, retcd; + int retcd; retcd = 0; - passthrough = mycheck_passthrough(cam); if (fileno(cam->extpipe_stream) > 0) { - if ((cam->imgs.size_high > 0) && (passthrough == false)) { + if ((cam->imgs.size_high > 0) && (cam->movie_passthrough == false)) { if (!fwrite(cam->current_image->image_high , cam->imgs.size_high, 1, cam->extpipe_stream)) { MOTPLS_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO diff --git a/src/netcam.cpp b/src/netcam.cpp index f12046d9..301c28b2 100644 --- a/src/netcam.cpp +++ b/src/netcam.cpp @@ -28,7 +28,6 @@ enum AVPixelFormat netcam_getfmt_vaapi(AVCodecContext *avctx, const enum AVPixelFormat *pix_fmts) { - #if ( MYFFVER >= 57083) const enum AVPixelFormat *p; (void)avctx; @@ -40,16 +39,10 @@ enum AVPixelFormat netcam_getfmt_vaapi(AVCodecContext *avctx, const enum AVPixel MOTPLS_LOG(ERR, TYPE_NETCAM, NO_ERRNO,_("Failed to get vaapi pix format")); return AV_PIX_FMT_NONE; - #else - (void)avctx; - (void)pix_fmts; - return AV_PIX_FMT_NONE; - #endif } enum AVPixelFormat netcam_getfmt_cuda(AVCodecContext *avctx, const enum AVPixelFormat *pix_fmts) { - #if ( MYFFVER >= 57083) const enum AVPixelFormat *p; (void)avctx; @@ -59,16 +52,10 @@ enum AVPixelFormat netcam_getfmt_cuda(AVCodecContext *avctx, const enum AVPixelF MOTPLS_LOG(ERR, TYPE_NETCAM, NO_ERRNO,_("Failed to get cuda pix format")); return AV_PIX_FMT_NONE; - #else - (void)avctx; - (void)pix_fmts; - return AV_PIX_FMT_NONE; - #endif } enum AVPixelFormat netcam_getfmt_drm(AVCodecContext *avctx, const enum AVPixelFormat *pix_fmts) { - #if ( MYFFVER >= 57083) const enum AVPixelFormat *p; (void)avctx; @@ -78,11 +65,6 @@ enum AVPixelFormat netcam_getfmt_drm(AVCodecContext *avctx, const enum AVPixelFo MOTPLS_LOG(ERR, TYPE_NETCAM, NO_ERRNO,_("Failed to get drm pix format")); return AV_PIX_FMT_NONE; - #else - (void)avctx; - (void)pix_fmts; - return AV_PIX_FMT_NONE; - #endif } int netcam_interrupt(void *ctx) @@ -353,7 +335,7 @@ void cls_netcam::url_parse(ctx_url *parse_url, std::string text_url) void cls_netcam::free_pkt() { - mypacket_free(packet_recv); + av_packet_free(&packet_recv); packet_recv = nullptr; } @@ -373,7 +355,7 @@ void cls_netcam::pktarray_free() pthread_mutex_lock(&mutex_pktarray); if (pktarray_size > 0) { for(indx = 0; indx < pktarray_size; indx++) { - mypacket_free(pktarray[indx].packet); + av_packet_free(&pktarray[indx].packet); pktarray[indx].packet = NULL; } } @@ -398,11 +380,11 @@ void cls_netcam::context_null() void cls_netcam::context_close() { if (swsctx != nullptr) sws_freeContext(swsctx); - if (swsframe_in != nullptr) myframe_free(swsframe_in); - if (swsframe_out != nullptr) myframe_free(swsframe_out); - if (frame != nullptr) myframe_free(frame); + if (swsframe_in != nullptr) av_frame_free(&swsframe_in); + if (swsframe_out != nullptr) av_frame_free(&swsframe_out); + if (frame != nullptr) av_frame_free(&frame); if (pktarray != nullptr) pktarray_free(); - if (codec_context != nullptr) myavcodec_close(codec_context); + if (codec_context != nullptr) avcodec_free_context(&codec_context); if (format_context != nullptr) avformat_close_input(&format_context); if (transfer_format != nullptr) avformat_close_input(&transfer_format); if (hw_device_ctx != nullptr) av_buffer_unref(&hw_device_ctx); @@ -500,18 +482,18 @@ void cls_netcam::pktarray_add() pktarray[indx_next].idnbr = idnbr; - mypacket_free(pktarray[indx_next].packet); + av_packet_free(&pktarray[indx_next].packet); pktarray[indx_next].packet = nullptr; pktarray[indx_next].packet = mypacket_alloc(pktarray[indx_next].packet); - retcd = mycopy_packet(pktarray[indx_next].packet, packet_recv); + retcd = av_packet_ref(pktarray[indx_next].packet, packet_recv); if ((interrupted) || (retcd < 0)) { av_strerror(retcd, errstr, sizeof(errstr)); MOTPLS_LOG(INF, TYPE_NETCAM, NO_ERRNO ,_("%s:av_copy_packet:%s ,Interrupt:%s") ,cameratype.c_str() ,errstr, interrupted ? _("true"):_("false")); - mypacket_free(pktarray[indx_next].packet); + av_packet_free(&pktarray[indx_next].packet); pktarray[indx_next].packet = nullptr; } @@ -528,7 +510,6 @@ void cls_netcam::pktarray_add() int cls_netcam::decode_sw() { - #if (MYFFVER >= 57041) int retcd; char errstr[128]; @@ -554,27 +535,22 @@ int cls_netcam::decode_sw() } return 1; - #else - (void)netcam; - return -1; - #endif } int cls_netcam::decode_vaapi() { - #if ( MYFFVER >= 57083) int retcd; char errstr[128]; AVFrame *hw_frame = nullptr; - hw_frame = myframe_alloc(); + hw_frame = av_frame_alloc(); retcd = av_hwframe_get_buffer(codec_context->hw_frames_ctx, hw_frame, 0); if (retcd < 0) { MOTPLS_LOG(INF, TYPE_NETCAM, NO_ERRNO , _("%s:Error getting hw frame buffer") , cameratype.c_str()); - myframe_free(hw_frame); + av_frame_free(&hw_frame); return -1; } @@ -596,7 +572,7 @@ int cls_netcam::decode_vaapi() } else { retcd = -1; } - myframe_free(hw_frame); + av_frame_free(&hw_frame); return retcd; } @@ -605,26 +581,21 @@ int cls_netcam::decode_vaapi() MOTPLS_LOG(INF, TYPE_NETCAM, NO_ERRNO ,_("%s:Error transferring HW decoded to system memory") ,cameratype.c_str()); - myframe_free(hw_frame); + av_frame_free(&hw_frame); return -1; } - myframe_free(hw_frame); + av_frame_free(&hw_frame); return 1; - #else - (void)netcam; - return -1; - #endif } int cls_netcam::decode_cuda() { - #if ( MYFFVER >= 57083) int retcd; char errstr[128]; AVFrame *hw_frame = nullptr; - hw_frame = myframe_alloc(); + hw_frame = av_frame_alloc(); retcd = avcodec_receive_frame(codec_context, hw_frame); if ((interrupted) || (finish) || (retcd < 0) ){ @@ -644,7 +615,7 @@ int cls_netcam::decode_cuda() } else { retcd = -1; } - myframe_free(hw_frame); + av_frame_free(&hw_frame); return retcd; } frame->format=AV_PIX_FMT_NV12; @@ -654,27 +625,22 @@ int cls_netcam::decode_cuda() MOTPLS_LOG(INF, TYPE_NETCAM, NO_ERRNO ,_("%s:Error transferring HW decoded to system memory") ,cameratype.c_str()); - myframe_free(hw_frame); + av_frame_free(&hw_frame); return -1; } - myframe_free(hw_frame); + av_frame_free(&hw_frame); return 1; - #else - (void)netcam; - return 1; - #endif } int cls_netcam::decode_drm() { - #if ( MYFFVER >= 57083) int retcd; char errstr[128]; AVFrame *hw_frame = nullptr; - hw_frame = myframe_alloc(); + hw_frame = av_frame_alloc(); retcd = avcodec_receive_frame(codec_context, hw_frame); if ((interrupted) || (finish) || (retcd < 0) ){ @@ -694,7 +660,7 @@ int cls_netcam::decode_drm() } else { retcd = -1; } - myframe_free(hw_frame); + av_frame_free(&hw_frame); return retcd; } frame->format=AV_PIX_FMT_NV12; @@ -704,22 +670,17 @@ int cls_netcam::decode_drm() MOTPLS_LOG(INF, TYPE_NETCAM, NO_ERRNO ,_("%s:Error transferring HW decoded to system memory") ,cameratype.c_str()); - myframe_free(hw_frame); + av_frame_free(&hw_frame); return -1; } - myframe_free(hw_frame); + av_frame_free(&hw_frame); return 1; - #else - (void)netcam; - return 1; - #endif } int cls_netcam::decode_video() { - #if (MYFFVER >= 57041) int retcd; char errstr[128]; @@ -768,40 +729,6 @@ int cls_netcam::decode_video() } return retcd; - - #else - int retcd; - int check = 0; - char errstr[128]; - - (void)decode_sw; - (void)decode_vaapi; - (void)decode_cuda; - (void)decode_drm; - - if (finish) { - return 0; - } - retcd = avcodec_decode_video2(codec_context, frame, &check, &packet_recv); - if ((interrupted) || (finish)) { - return -1; - } - if (retcd == AVERROR_INVALIDDATA) { - MOTPLS_LOG(INF, TYPE_NETCAM, NO_ERRNO, _("Ignoring packet with invalid data")); - return 0; - } - - if (retcd < 0) { - av_strerror(retcd, errstr, sizeof(errstr)); - MOTPLS_LOG(INF, TYPE_NETCAM, NO_ERRNO, _("Error decoding packet: %s"),errstr); - return -1; - } - - if (check == 0 || retcd == 0) { - return 0; - } - return 1; - #endif } int cls_netcam::decode_packet() @@ -823,19 +750,20 @@ int cls_netcam::decode_packet() if (retcd <= 0) { return retcd; } - frame_size = myimage_get_buffer_size((enum AVPixelFormat) frame->format - ,frame->width - ,frame->height); + frame_size = av_image_get_buffer_size( + (enum AVPixelFormat) frame->format + , frame->width, frame->height, 1); check_buffsize(img_recv, frame_size); check_buffsize(img_latest, frame_size); - retcd = myimage_copy_to_buffer(frame - ,(uint8_t *)img_recv->ptr - ,(enum AVPixelFormat) frame->format - ,frame->width - ,frame->height - ,frame_size); + retcd = av_image_copy_to_buffer( + (uint8_t *)img_recv->ptr + , frame_size + , (const uint8_t * const*)frame + , frame->linesize + , (enum AVPixelFormat)frame->format + , frame->width, frame->height, 1); if ((retcd < 0) || (interrupted)) { MOTPLS_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("%s:Error decoding video packet:Copying to buffer") @@ -850,7 +778,6 @@ int cls_netcam::decode_packet() void cls_netcam::hwdecoders() { - #if ( MYFFVER >= 57083) /* High Res pass through does not decode images into frames*/ if (high_resolution && passthrough) { return; @@ -876,10 +803,6 @@ void cls_netcam::hwdecoders() } } return; - #else - (void)netcam; - return; - #endif } void cls_netcam::decoder_error(int retcd, const char* fnc_nm) @@ -927,7 +850,6 @@ void cls_netcam::decoder_error(int retcd, const char* fnc_nm) int cls_netcam::init_vaapi() { - #if ( MYFFVER >= 57083) int retcd, indx; AVPixelFormat *pixelformats = nullptr; @@ -1015,8 +937,8 @@ int cls_netcam::init_vaapi() return -1; } /* Note that while these are listed as available, there - is currently no way to get them from HW decoder without - triggering a segfault in vaapi driver. + is currently no way to get them from HW decoder without + triggering a segfault in vaapi driver. */ const AVPixFmtDescriptor *descr; for (indx=0; pixelformats[indx] != AV_PIX_FMT_NONE; indx++) { @@ -1029,16 +951,10 @@ int cls_netcam::init_vaapi() av_freep(&pixelformats); return 0; - #else - (void)netcam; - (void)getfmt_vaapi; - return -1; - #endif } int cls_netcam::init_cuda() { - #if ( MYFFVER >= 57083) int retcd; MOTPLS_LOG(INF, TYPE_NETCAM, NO_ERRNO @@ -1080,16 +996,10 @@ int cls_netcam::init_cuda() codec_context->hw_device_ctx = av_buffer_ref(hw_device_ctx); return 0; - #else - (void)netcam; - (void)getfmt_cuda; - return 0; - #endif } int cls_netcam::init_drm() { - #if ( MYFFVER >= 57083) int retcd; MOTPLS_LOG(INF, TYPE_NETCAM, NO_ERRNO @@ -1132,16 +1042,10 @@ int cls_netcam::init_drm() codec_context->hw_device_ctx = av_buffer_ref(hw_device_ctx); return 0; - #else - (void)netcam; - (void)getfmt_drm; - return 0; - #endif } int cls_netcam::init_swdecoder() { - #if ( MYFFVER >= 57041) int retcd; MOTPLS_LOG(INF, TYPE_NETCAM, NO_ERRNO @@ -1184,27 +1088,10 @@ int cls_netcam::init_swdecoder() codec_context->err_recognition = AV_EF_EXPLODE; return 0; - #else - int retcd; - codec_context = strm->codec; - decoder = avcodec_find_decoder(codec_context->codec_id); - if ((decoder == nullptr) || (interrupted)) { - decoder_error(0, "avcodec_find_decoder"); - return -1; - } - retcd = avcodec_open2(codec_context, decoder, nullptr); - if ((retcd < 0) || (interrupted)) { - decoder_error(retcd, "avcodec_open2"); - return -1; - } - return 0; - #endif } int cls_netcam::open_codec() { - #if ( MYFFVER >= 57041) - int retcd; if (finish) { @@ -1241,7 +1128,7 @@ int cls_netcam::open_codec() decoder_error(retcd, "hwcuda_init"); return -1; } - } else if (decoder_nm == "drm"){ + } else if (decoder_nm == "drm"){ if (init_drm() < 0) {; decoder_error(retcd, "hwdrm_init"); return -1; @@ -1260,43 +1147,15 @@ int cls_netcam::open_codec() ,_("%s:Decoder opened"),cameratype.c_str()); return 0; - #else - int retcd; - - (void)init_vaapi; - (void)init_cuda; - (void)init_drm; - - if (finish) { - - return -1; - } - - hwdecoders(); - decoder = nullptr; - - retcd = av_find_best_stream(format_context, AVMEDIA_TYPE_VIDEO, -1, -1, nullptr, 0); - if ((retcd < 0) || (interrupted)) { - decoder_error(retcd, "av_find_best_stream"); - return -1; - } - video_stream_index = retcd; - strm = format_context->streams[video_stream_index]; - - retcd = init_swdecoder(); - - return retcd; - #endif } - int cls_netcam::open_sws() { if (finish) { return -1; } - swsframe_in = myframe_alloc(); + swsframe_in = av_frame_alloc(); if (swsframe_in == nullptr) { if (status == NETCAM_NOTCONNECTED) { MOTPLS_LOG(ERR, TYPE_NETCAM, NO_ERRNO @@ -1307,7 +1166,7 @@ int cls_netcam::open_sws() return -1; } - swsframe_out = myframe_alloc(); + swsframe_out = av_frame_alloc(); if (swsframe_out == nullptr) { if (status == NETCAM_NOTCONNECTED) { MOTPLS_LOG(ERR, TYPE_NETCAM, NO_ERRNO @@ -1348,10 +1207,8 @@ int cls_netcam::open_sws() return -1; } - swsframe_size = myimage_get_buffer_size( - MY_PIX_FMT_YUV420P - ,imgsize.width - ,imgsize.height); + swsframe_size = av_image_get_buffer_size( + MY_PIX_FMT_YUV420P, imgsize.width, imgsize.height, 1); if (swsframe_size <= 0) { if (status == NETCAM_NOTCONNECTED) { MOTPLS_LOG(ERR, TYPE_NETCAM, NO_ERRNO @@ -1384,13 +1241,12 @@ int cls_netcam::resize() return -1; } } - - retcd=myimage_fill_arrays( - swsframe_in - ,(uint8_t*)img_recv->ptr - ,(enum AVPixelFormat)frame->format - ,frame->width - ,frame->height); + retcd = av_image_fill_arrays( + swsframe_in->data + , swsframe_in->linesize + , (uint8_t*)img_recv->ptr + , (enum AVPixelFormat)frame->format + , frame->width, frame->height, 1); if (retcd < 0) { if (status == NETCAM_NOTCONNECTED) { av_strerror(retcd, errstr, sizeof(errstr)); @@ -1404,12 +1260,11 @@ int cls_netcam::resize() buffer_out=(uint8_t *)av_malloc(swsframe_size*sizeof(uint8_t)); - retcd=myimage_fill_arrays( - swsframe_out - ,buffer_out - ,MY_PIX_FMT_YUV420P - ,imgsize.width - ,imgsize.height); + retcd = av_image_fill_arrays( + swsframe_out->data + , swsframe_out->linesize + , buffer_out, MY_PIX_FMT_YUV420P + , imgsize.width, imgsize.height, 1); if (retcd < 0) { if (status == NETCAM_NOTCONNECTED) { av_strerror(retcd, errstr, sizeof(errstr)); @@ -1440,13 +1295,13 @@ int cls_netcam::resize() return -1; } - retcd=myimage_copy_to_buffer( - swsframe_out - ,(uint8_t *)img_recv->ptr - ,MY_PIX_FMT_YUV420P - ,imgsize.width - ,imgsize.height - ,swsframe_size); + retcd = av_image_copy_to_buffer( + (uint8_t *)img_recv->ptr + , swsframe_size + , (const uint8_t * const*)swsframe_out + , swsframe_out->linesize + , MY_PIX_FMT_YUV420P + , imgsize.width, imgsize.height, 1); if (retcd < 0) { if (status == NETCAM_NOTCONNECTED) { av_strerror(retcd, errstr, sizeof(errstr)); @@ -1804,7 +1659,6 @@ void cls_netcam::set_parms () , cameratype.c_str(), camera_name.c_str()); status = NETCAM_NOTCONNECTED; - mycheck_passthrough(cam); util_parms_add_default(params,"decoder","NULL"); img_recv =(netcam_buff_ptr) mymalloc(sizeof(netcam_buff)); img_recv->ptr =(char*) mymalloc(NETCAM_BUFFSIZE); @@ -1855,7 +1709,7 @@ void cls_netcam::set_parms () (cam->conf->netcam_high_url != "")) { passthrough = false; } else { - passthrough = mycheck_passthrough(cam); + passthrough = cam->movie_passthrough; } threadname = _("Unknown"); @@ -1875,8 +1729,6 @@ void cls_netcam::set_parms () /* Make a static copy of the stream information for use in passthrough processing */ int cls_netcam::copy_stream() { - /* Make a static copy of the stream information for use in passthrough processing */ - #if (MYFFVER >= 57041) AVStream *transfer_stream, *stream_in; int retcd, indx; @@ -1906,13 +1758,6 @@ int cls_netcam::copy_stream() MOTPLS_LOG(INF, TYPE_NETCAM, NO_ERRNO, _("Stream copied for pass-through")); return 0; - #else - /* This is disabled in the mycheck_passthrough but we need it here for compiling */ - if (netcam != nullptr) { - MOTPLS_LOG(INF, TYPE_ENCODER, NO_ERRNO, _("ffmpeg too old")); - } - return -1; - #endif } int cls_netcam::open_context() @@ -2014,7 +1859,7 @@ int cls_netcam::open_context() imgsize.height = codec_context->height; } - frame = myframe_alloc(); + frame = av_frame_alloc(); if (frame == nullptr) { if (status == NETCAM_NOTCONNECTED) { MOTPLS_LOG(ERR, TYPE_NETCAM, NO_ERRNO diff --git a/src/picture.cpp b/src/picture.cpp index b78db02a..83d782dc 100644 --- a/src/picture.cpp +++ b/src/picture.cpp @@ -262,11 +262,9 @@ int cls_picture::put_memory(u_char *img_dst, int image_size void cls_picture::pic_write(FILE *picture, u_char *image, int quality) { int width, height; - int passthrough; - passthrough = mycheck_passthrough(cam); if (((cam->filetype == FTYPE_IMAGE) || (cam->filetype == FTYPE_IMAGE_SNAPSHOT)) && - (cam->imgs.size_high > 0) && (!passthrough)) { + (cam->imgs.size_high > 0) && (cam->movie_passthrough == false)) { width = cam->imgs.width_high; height = cam->imgs.height_high; } else { diff --git a/src/util.cpp b/src/util.cpp index 83943b01..1510dfc4 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -628,24 +628,6 @@ void mythreadname_get(char *threadname) #endif } -bool mycheck_passthrough(ctx_dev *cam) -{ - #if (MYFFVER >= 57041) - if (cam->movie_passthrough) { - return true; - } else { - return false; - } - #else - if (cam->movie_passthrough) { - MOTPLS_LOG(INF, TYPE_NETCAM, NO_ERRNO - ,_("FFMPEG version too old. Disabling pass-through processing.")); - } - return false; - #endif - -} - static void mytranslate_locale_chg(const char *langcd) { #ifdef HAVE_GETTEXT @@ -727,26 +709,6 @@ char* mytranslate_text(const char *msgid, int setnls) ****************************************************************************/ /*********************************************/ /*********************************************/ -AVFrame *myframe_alloc(void) -{ - AVFrame *pic; - #if (MYFFVER >= 55000) - pic = av_frame_alloc(); - #else - pic = avcodec_alloc_frame(); - #endif - return pic; -} -/*********************************************/ -void myframe_free(AVFrame *frame) -{ - #if (MYFFVER >= 55000) - av_frame_free(&frame); - #else - av_freep(&frame); - #endif -} -/*********************************************/ void myframe_key(AVFrame *frame) { #if (MYFFVER < 60016) @@ -765,101 +727,11 @@ void myframe_interlaced(AVFrame *frame) #endif } - -/*********************************************/ -int myimage_get_buffer_size(enum MyPixelFormat pix_fmt, int width, int height) -{ - int retcd = 0; - #if (MYFFVER >= 57000) - int align = 1; - retcd = av_image_get_buffer_size(pix_fmt, width, height, align); - #else - retcd = avpicture_get_size(pix_fmt, width, height); - #endif - return retcd; -} -/*********************************************/ -int myimage_copy_to_buffer(AVFrame *frame, uint8_t *buffer_ptr, enum MyPixelFormat pix_fmt - , int width, int height, int dest_size) -{ - int retcd = 0; - #if (MYFFVER >= 57000) - int align = 1; - retcd = av_image_copy_to_buffer((uint8_t *)buffer_ptr,dest_size - ,(const uint8_t * const*)frame,frame->linesize,pix_fmt,width,height,align); - #else - retcd = avpicture_layout((const AVPicture*)frame,pix_fmt,width,height - ,(unsigned char *)buffer_ptr,dest_size); - #endif - return retcd; -} -/*********************************************/ -int myimage_fill_arrays(AVFrame *frame,uint8_t *buffer_ptr,enum MyPixelFormat pix_fmt - , int width,int height) -{ - int retcd = 0; - #if (MYFFVER >= 57000) - int align = 1; - retcd = av_image_fill_arrays( - frame->data - ,frame->linesize - ,buffer_ptr - ,pix_fmt - ,width - ,height - ,align - ); - #else - retcd = avpicture_fill( - (AVPicture *)frame - ,buffer_ptr - ,pix_fmt - ,width - ,height); - #endif - return retcd; -} -/*********************************************/ -void mypacket_free(AVPacket *pkt) -{ - #if (MYFFVER >= 57041) - av_packet_free(&pkt); - #else - av_free_packet(pkt); - #endif - -} -/*********************************************/ -void myavcodec_close(AVCodecContext *codec_context) -{ - #if (MYFFVER >= 57041) - avcodec_free_context(&codec_context); - #else - avcodec_close(codec_context); - #endif -} -/*********************************************/ -int mycopy_packet(AVPacket *dest_pkt, AVPacket *src_pkt) -{ - #if (MYFFVER >= 55000) - return av_packet_ref(dest_pkt, src_pkt); - #else - /* Old versions of libav do not support copying packet - * We therefore disable the pass through recording and - * for this function, simply do not do anything - */ - if (dest_pkt == src_pkt ) { - return 0; - } else { - return 0; - } - #endif -} /*********************************************/ AVPacket *mypacket_alloc(AVPacket *pkt) { if (pkt != NULL) { - mypacket_free(pkt); + av_packet_free(&pkt); }; pkt = av_packet_alloc(); #if (MYFFVER < 58076) diff --git a/src/util.hpp b/src/util.hpp index bc9cb54f..77094435 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -20,57 +20,27 @@ #ifndef _INCLUDE_UTIL_HPP_ #define _INCLUDE_UTIL_HPP_ -#if (MYFFVER >= 56000) - #define MY_PIX_FMT_YUV420P AV_PIX_FMT_YUV420P - #define MY_PIX_FMT_YUVJ420P AV_PIX_FMT_YUVJ420P - #define MyPixelFormat AVPixelFormat -#else //Old ffmpeg pixel formats - #define MY_PIX_FMT_YUV420P PIX_FMT_YUV420P - #define MY_PIX_FMT_YUVJ420P PIX_FMT_YUVJ420P - #define MyPixelFormat PixelFormat -#endif //Libavformat >= 56 +#define MY_PIX_FMT_YUV420P AV_PIX_FMT_YUV420P +#define MY_PIX_FMT_YUVJ420P AV_PIX_FMT_YUVJ420P +#define MyPixelFormat AVPixelFormat -#if (MYFFVER > 54006) - #define MY_FLAG_READ AVIO_FLAG_READ - #define MY_FLAG_WRITE AVIO_FLAG_WRITE - #define MY_FLAG_READ_WRITE AVIO_FLAG_READ_WRITE -#else //Older versions - #define MY_FLAG_READ URL_RDONLY - #define MY_FLAG_WRITE URL_WRONLY - #define MY_FLAG_READ_WRITE URL_RDWR -#endif +#define MY_FLAG_READ AVIO_FLAG_READ +#define MY_FLAG_WRITE AVIO_FLAG_WRITE +#define MY_FLAG_READ_WRITE AVIO_FLAG_READ_WRITE -#if (MYFFVER >= 56000) - #define MY_CODEC_ID_MSMPEG4V2 AV_CODEC_ID_MSMPEG4V2 - #define MY_CODEC_ID_FLV1 AV_CODEC_ID_FLV1 - #define MY_CODEC_ID_FFV1 AV_CODEC_ID_FFV1 - #define MY_CODEC_ID_NONE AV_CODEC_ID_NONE - #define MY_CODEC_ID_MPEG2VIDEO AV_CODEC_ID_MPEG2VIDEO - #define MY_CODEC_ID_H264 AV_CODEC_ID_H264 - #define MY_CODEC_ID_HEVC AV_CODEC_ID_HEVC - #define MY_CODEC_ID_THEORA AV_CODEC_ID_THEORA - #define MY_CODEC_ID_VP8 AV_CODEC_ID_VP8 - #define MY_CODEC_ID_VP9 AV_CODEC_ID_VP9 -#else - #define MY_CODEC_ID_MSMPEG4V2 CODEC_ID_MSMPEG4V2 - #define MY_CODEC_ID_FLV1 CODEC_ID_FLV1 - #define MY_CODEC_ID_FFV1 CODEC_ID_FFV1 - #define MY_CODEC_ID_NONE CODEC_ID_NONE - #define MY_CODEC_ID_MPEG2VIDEO CODEC_ID_MPEG2VIDEO - #define MY_CODEC_ID_H264 CODEC_ID_H264 - #define MY_CODEC_ID_HEVC CODEC_ID_H264 - #define MY_CODEC_ID_THEORA CODEC_ID_THEORA - #define MY_CODEC_ID_VP8 CODEC_ID_VP8 - #define MY_CODEC_ID_VP9 CODEC_ID_VP9 -#endif +#define MY_CODEC_ID_MSMPEG4V2 AV_CODEC_ID_MSMPEG4V2 +#define MY_CODEC_ID_FLV1 AV_CODEC_ID_FLV1 +#define MY_CODEC_ID_FFV1 AV_CODEC_ID_FFV1 +#define MY_CODEC_ID_NONE AV_CODEC_ID_NONE +#define MY_CODEC_ID_MPEG2VIDEO AV_CODEC_ID_MPEG2VIDEO +#define MY_CODEC_ID_H264 AV_CODEC_ID_H264 +#define MY_CODEC_ID_HEVC AV_CODEC_ID_HEVC +#define MY_CODEC_ID_THEORA AV_CODEC_ID_THEORA +#define MY_CODEC_ID_VP8 AV_CODEC_ID_VP8 +#define MY_CODEC_ID_VP9 AV_CODEC_ID_VP9 -#if (LIBAVCODEC_VERSION_MAJOR >= 57) - #define MY_CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER - #define MY_CODEC_FLAG_QSCALE AV_CODEC_FLAG_QSCALE -#else - #define MY_CODEC_FLAG_GLOBAL_HEADER CODEC_FLAG_GLOBAL_HEADER - #define MY_CODEC_FLAG_QSCALE CODEC_FLAG_QSCALE -#endif +#define MY_CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER +#define MY_CODEC_FLAG_QSCALE AV_CODEC_FLAG_QSCALE #if (LIBAVCODEC_VERSION_MAJOR >= 59) typedef const AVCodec myAVCodec; /* Version independent definition for AVCodec*/ @@ -121,7 +91,6 @@ void mythreadname_set(const char *abbr, int threadnbr, const char *threadname); void mythreadname_get(char *threadname); void mythreadname_get(std::string &threadname); - bool mycheck_passthrough(ctx_dev *cam); char* mytranslate_text(const char *msgid, int setnls); void mytranslate_init(void); @@ -135,16 +104,8 @@ void mytrim(std::string &parm); void myunquote(std::string &parm); - AVFrame *myframe_alloc(void); - void myframe_free(AVFrame *frame); void myframe_key(AVFrame *frame); void myframe_interlaced(AVFrame *frame); - void mypacket_free(AVPacket *pkt); - void myavcodec_close(AVCodecContext *codec_context); - int myimage_get_buffer_size(enum MyPixelFormat pix_fmt, int width, int height); - int myimage_copy_to_buffer(AVFrame *frame,uint8_t *buffer_ptr,enum MyPixelFormat pix_fmt,int width,int height,int dest_size); - int myimage_fill_arrays(AVFrame *frame,uint8_t *buffer_ptr,enum MyPixelFormat pix_fmt,int width,int height); - int mycopy_packet(AVPacket *dest_pkt, AVPacket *src_pkt); AVPacket *mypacket_alloc(AVPacket *pkt); void util_parms_parse(ctx_params *params, std::string parm_desc, std::string confline); diff --git a/src/webu_common.cpp b/src/webu_common.cpp index 9e17cccb..dc21bd3b 100644 --- a/src/webu_common.cpp +++ b/src/webu_common.cpp @@ -139,41 +139,47 @@ void cls_webu_common::img_resize(ctx_dev *p_cam img_sz = (dst_h * dst_w * 3)/2; memset(dst, 0x00, (size_t)img_sz); - frm_in = myframe_alloc(); + frm_in = av_frame_alloc(); if (frm_in == NULL) { MOTPLS_LOG(ERR, TYPE_NETCAM, NO_ERRNO , _("Unable to allocate frm_in.")); return; } - frm_out = myframe_alloc(); + frm_out = av_frame_alloc(); if (frm_out == NULL) { MOTPLS_LOG(ERR, TYPE_NETCAM, NO_ERRNO , _("Unable to allocate frm_out.")); - myframe_free(frm_in); + av_frame_free(&frm_in); return; } - retcd = myimage_fill_arrays(frm_in, src, MY_PIX_FMT_YUV420P, src_w, src_h); + retcd = av_image_fill_arrays( + frm_in->data, frm_in->linesize + , src, MY_PIX_FMT_YUV420P + , src_w, src_h, 1); if (retcd < 0) { av_strerror(retcd, errstr, sizeof(errstr)); MOTPLS_LOG(ERR, TYPE_NETCAM, NO_ERRNO , "Error filling arrays: %s", errstr); - myframe_free(frm_in); - myframe_free(frm_out); + av_frame_free(&frm_in); + av_frame_free(&frm_out); return; } buf = (uint8_t *)mymalloc((size_t)img_sz); - retcd = myimage_fill_arrays(frm_out, buf, MY_PIX_FMT_YUV420P, dst_w, dst_h); + retcd = av_image_fill_arrays( + frm_out->data, frm_out->linesize + , buf, MY_PIX_FMT_YUV420P + , dst_w, dst_h, 1); if (retcd < 0) { av_strerror(retcd, errstr, sizeof(errstr)); MOTPLS_LOG(ERR, TYPE_NETCAM, NO_ERRNO , "Error Filling array 2: %s", errstr); free(buf); - myframe_free(frm_in); - myframe_free(frm_out); + av_frame_free(&frm_in); + av_frame_free(&frm_out); return; } @@ -185,8 +191,8 @@ void cls_webu_common::img_resize(ctx_dev *p_cam MOTPLS_LOG(ERR, TYPE_NETCAM, NO_ERRNO , _("Unable to allocate scaling context.")); free(buf); - myframe_free(frm_in); - myframe_free(frm_out); + av_frame_free(&frm_in); + av_frame_free(&frm_out); return; } @@ -198,29 +204,32 @@ void cls_webu_common::img_resize(ctx_dev *p_cam MOTPLS_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("Error resizing/reformatting: %s"), errstr); free(buf); - myframe_free(frm_in); - myframe_free(frm_out); + av_frame_free(&frm_in); + av_frame_free(&frm_out); sws_freeContext(swsctx); return; } - retcd = myimage_copy_to_buffer( - frm_out, (uint8_t *)dst - ,MY_PIX_FMT_YUV420P, dst_w, dst_h, img_sz); + retcd = av_image_copy_to_buffer( + (uint8_t *)dst, img_sz + , (const uint8_t * const*)frm_out + , frm_out->linesize + , MY_PIX_FMT_YUV420P, dst_w, dst_h, 1); + if (retcd < 0) { av_strerror(retcd, errstr, sizeof(errstr)); MOTPLS_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("Error putting frame into output buffer: %s"), errstr); free(buf); - myframe_free(frm_in); - myframe_free(frm_out); + av_frame_free(&frm_in); + av_frame_free(&frm_out); sws_freeContext(swsctx); return; } free(buf); - myframe_free(frm_in); - myframe_free(frm_out); + av_frame_free(&frm_in); + av_frame_free(&frm_out); sws_freeContext(swsctx); } diff --git a/src/webu_mpegts.cpp b/src/webu_mpegts.cpp index de633e85..2208dd0c 100644 --- a/src/webu_mpegts.cpp +++ b/src/webu_mpegts.cpp @@ -54,7 +54,7 @@ int cls_webu_mpegts::pic_send(unsigned char *img) int64_t pts_interval; if (picture == NULL) { - picture = myframe_alloc(); + picture = av_frame_alloc(); picture->linesize[0] = ctx_codec->width; picture->linesize[1] = ctx_codec->width / 2; picture->linesize[2] = ctx_codec->width / 2; @@ -85,7 +85,7 @@ int cls_webu_mpegts::pic_send(unsigned char *img) av_strerror(retcd, errstr, sizeof(errstr)); MOTPLS_LOG(ERR, TYPE_STREAM, NO_ERRNO , _("Error sending frame for encoding:%s"), errstr); - myframe_free(picture); + av_frame_free(&picture); picture = NULL; return -1; } @@ -104,7 +104,7 @@ int cls_webu_mpegts::pic_get() retcd = avcodec_receive_packet(ctx_codec, pkt); if (retcd == AVERROR(EAGAIN)) { - mypacket_free(pkt); + av_packet_free(&pkt); pkt = NULL; return -1; } @@ -126,7 +126,7 @@ int cls_webu_mpegts::pic_get() return -1; } - mypacket_free(pkt); + av_packet_free(&pkt); pkt = NULL; return 0; @@ -421,11 +421,11 @@ cls_webu_mpegts::~cls_webu_mpegts() webua = nullptr; delete webuc; if (picture != nullptr) { - myframe_free(picture); + av_frame_free(&picture); picture = nullptr; } if (ctx_codec != nullptr) { - myavcodec_close(ctx_codec); + avcodec_free_context(&ctx_codec); ctx_codec = nullptr; } if (fmtctx != nullptr) {