From 0386ce6915d5285254e97ad24f14d2566f736490 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Wed, 1 Nov 2017 06:57:33 +0200 Subject: [PATCH] motion: remove some patches applied upstream --- .../motion/0011-do-not-force-keyframe.patch | 40 ---- .../0012-decouple-avcodec-send-receive.patch | 182 ------------------ package/motion/0013-drain-codec.patch | 140 -------------- 3 files changed, 362 deletions(-) delete mode 100644 package/motion/0011-do-not-force-keyframe.patch delete mode 100644 package/motion/0012-decouple-avcodec-send-receive.patch delete mode 100644 package/motion/0013-drain-codec.patch diff --git a/package/motion/0011-do-not-force-keyframe.patch b/package/motion/0011-do-not-force-keyframe.patch deleted file mode 100644 index 7eb9c1f3a7..0000000000 --- a/package/motion/0011-do-not-force-keyframe.patch +++ /dev/null @@ -1,40 +0,0 @@ -diff --git a/ffmpeg.c b/ffmpeg.c -index 739bcb3..aa17ddc 100644 ---- a/ffmpeg.c -+++ b/ffmpeg.c -@@ -349,8 +349,6 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - //Packet is freed upon failure of encoding - return -1; - } -- if (ffmpeg->picture->key_frame == 1) -- ffmpeg->pkt.flags |= AV_PKT_FLAG_KEY; - - return 0; - -@@ -373,9 +371,6 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - return -2; - } - -- if (ffmpeg->picture->key_frame == 1) -- ffmpeg->pkt.flags |= AV_PKT_FLAG_KEY; -- - return 0; - - #else -@@ -399,12 +394,16 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - return -2; - } - -+ // Encoder did not provide metadata, set it up manually - ffmpeg->pkt.size = retcd; - ffmpeg->pkt.data = video_outbuf; - - if (ffmpeg->picture->key_frame == 1) - ffmpeg->pkt.flags |= AV_PKT_FLAG_KEY; - -+ ffmpeg->pkt.pts = ffmpeg->picture->pts; -+ ffmpeg->pkt.dts = ffmpeg->pkt.pts; -+ - free(video_outbuf); - - return 0; diff --git a/package/motion/0012-decouple-avcodec-send-receive.patch b/package/motion/0012-decouple-avcodec-send-receive.patch deleted file mode 100644 index 562e358788..0000000000 --- a/package/motion/0012-decouple-avcodec-send-receive.patch +++ /dev/null @@ -1,182 +0,0 @@ -commit 2220065f0e2240e963aeb9bc99fd7c233ea2834d -Author: Joo Aun Saw -Date: Mon Sep 18 14:21:36 2017 +1000 - - decouple avcodec send receive - -diff --git a/ffmpeg.c b/ffmpeg.c -index 560e7d4..aa06bef 100644 ---- a/ffmpeg.c -+++ b/ffmpeg.c -@@ -341,6 +341,15 @@ static int ffmpeg_get_oformat(struct ffmpeg *ffmpeg){ - return 0; - } - -+static int ffmpeg_write_packet(struct ffmpeg *ffmpeg){ -+ -+ if (ffmpeg->tlapse == TIMELAPSE_APPEND) { -+ return ffmpeg_timelapse_append(ffmpeg, ffmpeg->pkt); -+ } else { -+ return av_write_frame(ffmpeg->oc, &ffmpeg->pkt); -+ } -+} -+ - static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - - #if (LIBAVFORMAT_VERSION_MAJOR >= 58) || ((LIBAVFORMAT_VERSION_MAJOR == 57) && (LIBAVFORMAT_VERSION_MINOR >= 41)) -@@ -348,25 +357,41 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - int retcd = 0; - char errstr[128]; - -+ av_init_packet(&ffmpeg->pkt); -+ ffmpeg->pkt.data = NULL; -+ ffmpeg->pkt.size = 0; -+ - retcd = avcodec_send_frame(ffmpeg->ctx_codec, ffmpeg->picture); - if (retcd < 0 ){ - av_strerror(retcd, errstr, sizeof(errstr)); - MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error sending frame for encoding:%s",errstr); -- return -1; -- } -- retcd = avcodec_receive_packet(ffmpeg->ctx_codec, &ffmpeg->pkt); -- if (retcd == AVERROR(EAGAIN)){ -- //Buffered packet. Throw special return code - my_packet_unref(ffmpeg->pkt); -- return -2; -- } -- if (retcd < 0 ){ -- av_strerror(retcd, errstr, sizeof(errstr)); -- MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error receiving encoded packet video:%s",errstr); -- //Packet is freed upon failure of encoding - return -1; - } -+ while (retcd >= 0) { -+ retcd = avcodec_receive_packet(ffmpeg->ctx_codec, &ffmpeg->pkt); -+ if (retcd == AVERROR(EAGAIN)){ -+ //Buffered packet. Throw special return code -+ my_packet_unref(ffmpeg->pkt); -+ return -2; -+ } -+ if (retcd < 0 ){ -+ av_strerror(retcd, errstr, sizeof(errstr)); -+ MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error receiving encoded packet video:%s",errstr); -+ my_packet_unref(ffmpeg->pkt); -+ return -1; -+ } else { -+ retcd = ffmpeg_write_packet(ffmpeg); -+ if (retcd < 0) { -+ MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error while writing video frame"); -+ my_packet_unref(ffmpeg->pkt); -+ ffmpeg_free_context(ffmpeg); -+ return -1; -+ } -+ } -+ } - -+ my_packet_unref(ffmpeg->pkt); - return 0; - - #elif (LIBAVFORMAT_VERSION_MAJOR >= 55) || ((LIBAVFORMAT_VERSION_MAJOR == 54) && (LIBAVFORMAT_VERSION_MINOR > 6)) -@@ -375,11 +400,15 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - char errstr[128]; - int got_packet_ptr; - -+ av_init_packet(&ffmpeg->pkt); -+ ffmpeg->pkt.data = NULL; -+ ffmpeg->pkt.size = 0; -+ - retcd = avcodec_encode_video2(ffmpeg->ctx_codec, &ffmpeg->pkt, ffmpeg->picture, &got_packet_ptr); - if (retcd < 0 ){ - av_strerror(retcd, errstr, sizeof(errstr)); - MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error encoding video:%s",errstr); -- //Packet is freed upon failure of encoding -+ my_packet_unref(ffmpeg->pkt); - return -1; - } - if (got_packet_ptr == 0){ -@@ -388,6 +417,15 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - return -2; - } - -+ retcd = ffmpeg_write_packet(ffmpeg); -+ if (retcd < 0) { -+ MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error while writing video frame"); -+ my_packet_unref(ffmpeg->pkt); -+ ffmpeg_free_context(ffmpeg); -+ return -1; -+ } -+ -+ my_packet_unref(ffmpeg->pkt); - return 0; - - #else -@@ -396,6 +434,10 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - uint8_t *video_outbuf; - int video_outbuf_size; - -+ av_init_packet(&ffmpeg->pkt); -+ ffmpeg->pkt.data = NULL; -+ ffmpeg->pkt.size = 0; -+ - video_outbuf_size = (ffmpeg->ctx_codec->width +16) * (ffmpeg->ctx_codec->height +16) * 1; - video_outbuf = mymalloc(video_outbuf_size); - -@@ -421,8 +463,18 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - ffmpeg->pkt.pts = ffmpeg->picture->pts; - ffmpeg->pkt.dts = ffmpeg->pkt.pts; - -- free(video_outbuf); -+ retcd = ffmpeg_write_packet(ffmpeg); -+ if (retcd < 0) { -+ av_strerror(retcd, errstr, sizeof(errstr)); -+ MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error while writing video frame"); -+ my_packet_unref(ffmpeg->pkt); -+ free(video_outbuf); -+ ffmpeg_free_context(ffmpeg); -+ return -1; -+ } - -+ my_packet_unref(ffmpeg->pkt); -+ free(video_outbuf); - return 0; - - #endif -@@ -759,35 +811,16 @@ static int ffmpeg_set_outputfile(struct ffmpeg *ffmpeg){ - static int ffmpeg_put_frame(struct ffmpeg *ffmpeg, const struct timeval *tv1){ - int retcd; - -- av_init_packet(&ffmpeg->pkt); -- ffmpeg->pkt.data = NULL; -- ffmpeg->pkt.size = 0; -- - retcd = ffmpeg_set_pts(ffmpeg, tv1); - if (retcd < 0) { - //If there is an error, it has already been reported. -- my_packet_unref(ffmpeg->pkt); - return 0; - } - - retcd = ffmpeg_encode_video(ffmpeg); -- if (retcd != 0){ -- MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error while encoding picture"); -- my_packet_unref(ffmpeg->pkt); -- return retcd; -- } -- -- if (ffmpeg->tlapse == TIMELAPSE_APPEND) { -- retcd = ffmpeg_timelapse_append(ffmpeg, ffmpeg->pkt); -- } else { -- retcd = av_write_frame(ffmpeg->oc, &ffmpeg->pkt); -- } -- my_packet_unref(ffmpeg->pkt); -- -- if (retcd < 0) { -- MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error while writing video frame"); -- ffmpeg_free_context(ffmpeg); -- return -1; -+ if (retcd < 0){ -+ if (retcd != -2) -+ MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error while encoding picture"); - } - return retcd; - diff --git a/package/motion/0013-drain-codec.patch b/package/motion/0013-drain-codec.patch deleted file mode 100644 index 480403a1ea..0000000000 --- a/package/motion/0013-drain-codec.patch +++ /dev/null @@ -1,140 +0,0 @@ -commit ff55aecd6fb88a030790b494dcd55bd99cace52b -Author: Joo Aun Saw -Date: Mon Sep 18 16:25:44 2017 +1000 - - drain codec at end of recording - -diff --git a/ffmpeg.c b/ffmpeg.c -index aa06bef..ecdc3e5 100644 ---- a/ffmpeg.c -+++ b/ffmpeg.c -@@ -350,7 +350,7 @@ static int ffmpeg_write_packet(struct ffmpeg *ffmpeg){ - } - } - --static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ -+static int ffmpeg_encode_video(struct ffmpeg *ffmpeg, AVFrame *picture){ - - #if (LIBAVFORMAT_VERSION_MAJOR >= 58) || ((LIBAVFORMAT_VERSION_MAJOR == 57) && (LIBAVFORMAT_VERSION_MINOR >= 41)) - //ffmpeg version 3.1 and after -@@ -361,7 +361,7 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - ffmpeg->pkt.data = NULL; - ffmpeg->pkt.size = 0; - -- retcd = avcodec_send_frame(ffmpeg->ctx_codec, ffmpeg->picture); -+ retcd = avcodec_send_frame(ffmpeg->ctx_codec, picture); - if (retcd < 0 ){ - av_strerror(retcd, errstr, sizeof(errstr)); - MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error sending frame for encoding:%s",errstr); -@@ -370,10 +370,15 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - } - while (retcd >= 0) { - retcd = avcodec_receive_packet(ffmpeg->ctx_codec, &ffmpeg->pkt); -- if (retcd == AVERROR(EAGAIN)){ -- //Buffered packet. Throw special return code -- my_packet_unref(ffmpeg->pkt); -- return -2; -+ if (picture == NULL) { -+ if (retcd == AVERROR_EOF) -+ break; -+ } else { -+ if (retcd == AVERROR(EAGAIN)){ -+ //Buffered packet. Throw special return code -+ my_packet_unref(ffmpeg->pkt); -+ return -2; -+ } - } - if (retcd < 0 ){ - av_strerror(retcd, errstr, sizeof(errstr)); -@@ -385,7 +390,11 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - if (retcd < 0) { - MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error while writing video frame"); - my_packet_unref(ffmpeg->pkt); -- ffmpeg_free_context(ffmpeg); -+ /* Do not free ffmpeg context if we are draining codec. We still -+ * need to write trailer even if draining fails. -+ */ -+ if (picture != NULL) -+ ffmpeg_free_context(ffmpeg); - return -1; - } - } -@@ -404,7 +413,7 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - ffmpeg->pkt.data = NULL; - ffmpeg->pkt.size = 0; - -- retcd = avcodec_encode_video2(ffmpeg->ctx_codec, &ffmpeg->pkt, ffmpeg->picture, &got_packet_ptr); -+ retcd = avcodec_encode_video2(ffmpeg->ctx_codec, &ffmpeg->pkt, picture, &got_packet_ptr); - if (retcd < 0 ){ - av_strerror(retcd, errstr, sizeof(errstr)); - MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error encoding video:%s",errstr); -@@ -421,7 +430,11 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - if (retcd < 0) { - MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error while writing video frame"); - my_packet_unref(ffmpeg->pkt); -- ffmpeg_free_context(ffmpeg); -+ /* Do not free ffmpeg context if we are draining codec. We still -+ * need to write trailer even if draining fails. -+ */ -+ if (picture != NULL) -+ ffmpeg_free_context(ffmpeg); - return -1; - } - -@@ -441,7 +454,7 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - video_outbuf_size = (ffmpeg->ctx_codec->width +16) * (ffmpeg->ctx_codec->height +16) * 1; - video_outbuf = mymalloc(video_outbuf_size); - -- retcd = avcodec_encode_video(ffmpeg->video_st->codec, video_outbuf, video_outbuf_size, ffmpeg->picture); -+ retcd = avcodec_encode_video(ffmpeg->video_st->codec, video_outbuf, video_outbuf_size, picture); - if (retcd < 0 ){ - MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error encoding video"); - my_packet_unref(ffmpeg->pkt); -@@ -457,11 +470,12 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - ffmpeg->pkt.size = retcd; - ffmpeg->pkt.data = video_outbuf; - -- if (ffmpeg->picture->key_frame == 1) -- ffmpeg->pkt.flags |= AV_PKT_FLAG_KEY; -- -- ffmpeg->pkt.pts = ffmpeg->picture->pts; -- ffmpeg->pkt.dts = ffmpeg->pkt.pts; -+ if (picture) { -+ if (picture->key_frame == 1) -+ ffmpeg->pkt.flags |= AV_PKT_FLAG_KEY; -+ ffmpeg->pkt.pts = picture->pts; -+ ffmpeg->pkt.dts = ffmpeg->pkt.pts; -+ } - - retcd = ffmpeg_write_packet(ffmpeg); - if (retcd < 0) { -@@ -469,7 +483,11 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg){ - MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error while writing video frame"); - my_packet_unref(ffmpeg->pkt); - free(video_outbuf); -- ffmpeg_free_context(ffmpeg); -+ /* Do not free ffmpeg context if we are draining codec. We still -+ * need to write trailer even if draining fails. -+ */ -+ if (picture != NULL) -+ ffmpeg_free_context(ffmpeg); - return -1; - } - -@@ -817,7 +835,7 @@ static int ffmpeg_put_frame(struct ffmpeg *ffmpeg, const struct timeval *tv1){ - return 0; - } - -- retcd = ffmpeg_encode_video(ffmpeg); -+ retcd = ffmpeg_encode_video(ffmpeg, ffmpeg->picture); - if (retcd < 0){ - if (retcd != -2) - MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "Error while encoding picture"); -@@ -957,6 +975,7 @@ void ffmpeg_close(struct ffmpeg *ffmpeg){ - #ifdef HAVE_FFMPEG - - if (ffmpeg != NULL) { -+ ffmpeg_encode_video(ffmpeg, NULL); // drain codec - if (ffmpeg->tlapse != TIMELAPSE_APPEND) { - av_write_trailer(ffmpeg->oc); - }