[FFmpeg-cvslog] avformat/http: support retry on connection error

2021-01-03 Thread erankor
ffmpeg | branch: master | erankor  | Thu Dec  3 
10:42:52 2020 +0200| [fde5593c7ce5288ae1333e9dc3ca4f95caa69444] | committer: 
Marton Balint

avformat/http: support retry on connection error

Add 2 new options:
- reconnect_on_http_error - a list of http status codes that should be
retried. the list can contain explicit status codes / the strings
4xx/5xx.
- reconnect_on_network_error - reconnects on arbitrary errors during
connect, e.g. ECONNRESET/ETIMEDOUT

the retry employs the same exponential backoff logic as the existing
reconnect/reconnect_at_eof flags.

related tickets:
https://trac.ffmpeg.org/ticket/6066
https://trac.ffmpeg.org/ticket/7768

Signed-off-by: Marton Balint 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fde5593c7ce5288ae1333e9dc3ca4f95caa69444
---

 doc/protocols.texi|  7 ++
 libavformat/http.c| 60 +--
 libavformat/version.h |  2 +-
 3 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index 00a6665482..af887761e9 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -410,6 +410,13 @@ for live / endless streams.
 @item reconnect_streamed
 If set then even streamed/non seekable streams will be reconnected on errors.
 
+@item reconnect_on_network_error
+Reconnect automatically in case of TCP/TLS errors during connect.
+
+@item reconnect_on_http_error
+A comma separated list of HTTP status codes to reconnect on. The list can
+include specific status codes (e.g. '503') or the strings '4xx' / '5xx'.
+
 @item reconnect_delay_max
 Sets the maximum delay in seconds after which to give up reconnecting
 
diff --git a/libavformat/http.c b/libavformat/http.c
index 2d24c00e18..76f0a67c61 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -119,8 +119,10 @@ typedef struct HTTPContext {
 char *method;
 int reconnect;
 int reconnect_at_eof;
+int reconnect_on_network_error;
 int reconnect_streamed;
 int reconnect_delay_max;
+char *reconnect_on_http_error;
 int listen;
 char *resource;
 int reply_code;
@@ -164,6 +166,8 @@ static const AVOption options[] = {
 { "method", "Override the HTTP method or set the expected HTTP method from 
a client", OFFSET(method), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D | E },
 { "reconnect", "auto reconnect after disconnect before EOF", 
OFFSET(reconnect), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, D },
 { "reconnect_at_eof", "auto reconnect at EOF", OFFSET(reconnect_at_eof), 
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, D },
+{ "reconnect_on_network_error", "auto reconnect in case of tcp/tls error 
during connect", OFFSET(reconnect_on_network_error), AV_OPT_TYPE_BOOL, { .i64 = 
0 }, 0, 1, D },
+{ "reconnect_on_http_error", "list of http status codes to reconnect on", 
OFFSET(reconnect_on_http_error), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D },
 { "reconnect_streamed", "auto reconnect streamed / non seekable streams", 
OFFSET(reconnect_streamed), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, D },
 { "reconnect_delay_max", "max reconnect delay in seconds after which to 
give up", OFFSET(reconnect_delay_max), AV_OPT_TYPE_INT, { .i64 = 120 }, 0, 
UINT_MAX/1000/1000, D },
 { "listen", "listen on HTTP", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 
}, 0, 2, D | E },
@@ -258,21 +262,73 @@ static int http_open_cnx_internal(URLContext *h, 
AVDictionary **options)
 return location_changed;
 }
 
+static int http_should_reconnect(HTTPContext *s, int err)
+{
+const char *status_group;
+char http_code[4];
+
+switch (err) {
+case AVERROR_HTTP_BAD_REQUEST:
+case AVERROR_HTTP_UNAUTHORIZED:
+case AVERROR_HTTP_FORBIDDEN:
+case AVERROR_HTTP_NOT_FOUND:
+case AVERROR_HTTP_OTHER_4XX:
+status_group = "4xx";
+break;
+
+case AVERROR_HTTP_SERVER_ERROR:
+status_group = "5xx";
+break;
+
+default:
+return s->reconnect_on_network_error;
+}
+
+if (!s->reconnect_on_http_error)
+return 0;
+
+if (av_match_list(status_group, s->reconnect_on_http_error, ',') > 0)
+return 1;
+
+snprintf(http_code, sizeof(http_code), "%d", s->http_code);
+
+return av_match_list(http_code, s->reconnect_on_http_error, ',') > 0;
+}
+
 /* return non zero if error */
 static int http_open_cnx(URLContext *h, AVDictionary **options)
 {
 HTTPAuthType cur_auth_type, cur_proxy_auth_type;
 HTTPContext *s = h->priv_data;
 int location_changed, attempts = 0, redirects = 0;
+int reconnect_delay = 0;
+uint64_t off;
+
 redo:
 av_dict_copy(options, s->chained_options, 0);
 
 cur_auth_type   = s->auth_state.auth_type;
 cur_proxy_auth_type = s->auth_state.auth_type;
 
+off = s->off;
 location_changed = http_open_cnx_internal(h, options);
-if (location_changed < 0)
-goto fail;
+if (location_changed < 0) {
+if (!http_should_reconnect(s, location_changed) ||

[FFmpeg-cvslog] avfilter/vf_w3fdif: add two more useful options

2021-01-03 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Sun Jan  3 22:20:55 
2021 +0100| [b112c86a2eaefb3a28fd851ed8cca579b3d79f1a] | committer: Paul B Mahol

avfilter/vf_w3fdif: add two more useful options

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b112c86a2eaefb3a28fd851ed8cca579b3d79f1a
---

 doc/filters.texi| 29 +
 libavfilter/vf_w3fdif.c | 19 +++
 2 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 01ae540c5c..813e35c2f9 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -20931,6 +20931,35 @@ More-complex filter coefficient set.
 @end table
 Default value is @samp{complex}.
 
+@item mode
+The interlacing mode to adopt. It accepts one of the following values:
+
+@table @option
+@item frame
+Output one frame for each frame.
+@item field
+Output one frame for each field.
+@end table
+
+The default value is @code{field}.
+
+@item parity
+The picture field parity assumed for the input interlaced video. It accepts one
+of the following values:
+
+@table @option
+@item tff
+Assume the top field is first.
+@item bff
+Assume the bottom field is first.
+@item auto
+Enable automatic detection of field parity.
+@end table
+
+The default value is @code{auto}.
+If the interlacing is unknown or the decoder does not export this information,
+top field first will be assumed.
+
 @item deint
 Specify which frames to deinterlace. Accepts one of the following values:
 
diff --git a/libavfilter/vf_w3fdif.c b/libavfilter/vf_w3fdif.c
index c7c6984241..685f7679f0 100644
--- a/libavfilter/vf_w3fdif.c
+++ b/libavfilter/vf_w3fdif.c
@@ -34,6 +34,8 @@
 typedef struct W3FDIFContext {
 const AVClass *class;
 int filter;   ///< 0 is simple, 1 is more complex
+int mode; ///< 0 is frame, 1 is field
+int parity;   ///< frame field parity
 int deint;///< which frames to deinterlace
 int linesize[4];  ///< bytes of pixel data per line for each plane
 int planeheight[4];   ///< height of each plane
@@ -56,6 +58,13 @@ static const AVOption w3fdif_options[] = {
 { "filter", "specify the filter", OFFSET(filter), AV_OPT_TYPE_INT, 
{.i64=1}, 0, 1, FLAGS, "filter" },
 CONST("simple",  NULL, 0, "filter"),
 CONST("complex", NULL, 1, "filter"),
+{ "mode",   "specify the interlacing mode", OFFSET(mode), AV_OPT_TYPE_INT, 
{.i64=1}, 0, 1, FLAGS, "mode"},
+CONST("frame", "send one frame for each frame", 0, "mode"),
+CONST("field", "send one frame for each field", 1, "mode"),
+{ "parity", "specify the assumed picture field parity", OFFSET(parity), 
AV_OPT_TYPE_INT, {.i64=-1}, -1, 1, FLAGS, "parity" },
+CONST("tff",  "assume top field first", 0, "parity"),
+CONST("bff",  "assume bottom field first",  1, "parity"),
+CONST("auto", "auto detect parity",-1, "parity"),
 { "deint",  "specify which frames to deinterlace", OFFSET(deint), 
AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "deint" },
 CONST("all","deinterlace all frames",   0, 
"deint"),
 CONST("interlaced", "only deinterlace frames marked as interlaced", 1, 
"deint"),
@@ -372,10 +381,11 @@ static int deinterlace_slice(AVFilterContext *ctx, void 
*arg, int jobnr, int nb_
 const int start = (height * jobnr) / nb_jobs;
 const int end = (height * (jobnr+1)) / nb_jobs;
 const int max = s->max;
+const int tff = s->field == (s->parity == -1 ? cur->top_field_first == 1 : 
s->parity == 0 ? 1 : 0);
 int j, y_in, y_out;
 
 /* copy unchanged the lines of the field */
-y_out = start + ((s->field == cur->top_field_first) ^ (start & 1));
+y_out = start + (tff ^ (start & 1));
 
 in_line  = cur_data + (y_out * cur_line_stride);
 out_line = dst_data + (y_out * dst_line_stride);
@@ -388,7 +398,7 @@ static int deinterlace_slice(AVFilterContext *ctx, void 
*arg, int jobnr, int nb_
 }
 
 /* interpolate other lines of the field */
-y_out = start + ((s->field != cur->top_field_first) ^ (start & 1));
+y_out = start + ((!tff) ^ (start & 1));
 
 out_line = dst_data + (y_out * dst_line_stride);
 
@@ -489,7 +499,8 @@ static int filter(AVFilterContext *ctx, int is_second)
 ctx->internal->execute(ctx, deinterlace_slice, &td, NULL, 
FFMIN(s->planeheight[plane], s->nb_threads));
 }
 
-s->field = !s->field;
+if (s->mode)
+s->field = !s->field;
 
 return ff_filter_frame(outlink, out);
 }
@@ -526,7 +537,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
 return 0;
 
 ret = filter(ctx, 0);
-if (ret < 0)
+if (ret < 0 || s->mode == 0)
 return ret;
 
 return filter(ctx, 1);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avfilter/vf_w3fdif: not interlaced frames are filtered like tff

2021-01-03 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Sun Jan  3 22:48:40 
2021 +0100| [ddd6c5cdc05fe889f6d0b88e3237e7db564bf2ea] | committer: Paul B Mahol

avfilter/vf_w3fdif: not interlaced frames are filtered like tff

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ddd6c5cdc05fe889f6d0b88e3237e7db564bf2ea
---

 libavfilter/vf_w3fdif.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vf_w3fdif.c b/libavfilter/vf_w3fdif.c
index 685f7679f0..bbf1d026e2 100644
--- a/libavfilter/vf_w3fdif.c
+++ b/libavfilter/vf_w3fdif.c
@@ -381,7 +381,7 @@ static int deinterlace_slice(AVFilterContext *ctx, void 
*arg, int jobnr, int nb_
 const int start = (height * jobnr) / nb_jobs;
 const int end = (height * (jobnr+1)) / nb_jobs;
 const int max = s->max;
-const int tff = s->field == (s->parity == -1 ? cur->top_field_first == 1 : 
s->parity == 0 ? 1 : 0);
+const int tff = (s->field == (s->parity == -1 ? cur->top_field_first == 
cur->interlaced_frame : s->parity == 0 ? !cur->interlaced_frame : 
cur->interlaced_frame));
 int j, y_in, y_out;
 
 /* copy unchanged the lines of the field */

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avformat/rtpdec: export Opus extradata in ff_rtp_parse_open()

2021-01-03 Thread Jonathan Baudanza
ffmpeg | branch: master | Jonathan Baudanza  | Tue Dec 29 
10:07:11 2020 -0800| [6c24f2bf410a41587cf523e1faea3e5f2d4c3590] | committer: 
James Almer

avformat/rtpdec: export Opus extradata in ff_rtp_parse_open()

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6c24f2bf410a41587cf523e1faea3e5f2d4c3590
---

 libavformat/rtpdec.c | 51 +++
 1 file changed, 51 insertions(+)

diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index 3d5b200099..51cf0fde07 100644
--- a/libavformat/rtpdec.c
+++ b/libavformat/rtpdec.c
@@ -24,12 +24,15 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/time.h"
 
+#include "libavcodec/bytestream.h"
+
 #include "avformat.h"
 #include "network.h"
 #include "srtp.h"
 #include "url.h"
 #include "rtpdec.h"
 #include "rtpdec_formats.h"
+#include "internal.h"
 
 #define MIN_FEEDBACK_INTERVAL 20 /* 200 ms in us */
 
@@ -529,6 +532,43 @@ int ff_rtp_send_rtcp_feedback(RTPDemuxContext *s, 
URLContext *fd,
 return 0;
 }
 
+static int opus_write_extradata(AVCodecParameters *codecpar)
+{
+uint8_t *bs;
+int ret;
+
+/* This function writes an extradata with a channel mapping family of 0.
+ * This mapping family only supports mono and stereo layouts. And RFC7587
+ * specifies that the number of channels in the SDP must be 2.
+ */
+if (codecpar->channels > 2) {
+return AVERROR_INVALIDDATA;
+}
+
+ret = ff_alloc_extradata(codecpar, 19);
+if (ret < 0)
+return ret;
+
+bs = (uint8_t *)codecpar->extradata;
+
+/* Opus magic */
+bytestream_put_buffer(&bs, "OpusHead", 8);
+/* Version */
+bytestream_put_byte  (&bs, 0x1);
+/* Channel count */
+bytestream_put_byte  (&bs, codecpar->channels);
+/* Pre skip */
+bytestream_put_le16  (&bs, 0);
+/* Input sample rate */
+bytestream_put_le32  (&bs, 48000);
+/* Output gain */
+bytestream_put_le16  (&bs, 0x0);
+/* Mapping family */
+bytestream_put_byte  (&bs, 0x0);
+
+return 0;
+}
+
 /**
  * open a new RTP parse context for stream 'st'. 'st' can be NULL for
  * MPEG-2 TS streams.
@@ -537,6 +577,7 @@ RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, 
AVStream *st,
int payload_type, int queue_size)
 {
 RTPDemuxContext *s;
+int ret;
 
 s = av_mallocz(sizeof(RTPDemuxContext));
 if (!s)
@@ -560,6 +601,16 @@ RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, 
AVStream *st,
 if (st->codecpar->sample_rate == 8000)
 st->codecpar->sample_rate = 16000;
 break;
+case AV_CODEC_ID_OPUS:
+ret = opus_write_extradata(st->codecpar);
+if (ret < 0) {
+av_log(s1, AV_LOG_ERROR,
+   "Error creating opus extradata: %s\n",
+   av_err2str(ret));
+av_free(s);
+return NULL;
+}
+break;
 default:
 break;
 }

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".