Opened 6 years ago
Last modified 5 years ago
#7339 new enhancement
HLS-Retry mechanism for HTTP-Upload segments
Reported by: | Martini | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | avformat |
Version: | git-master | Keywords: | hls |
Cc: | Blocked By: | ||
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
Summary of the enhancement:
Retry hls-segment upload once, if web server returns HTTP 500.
How to reproduce:
% ffmpeg -i http://wdr-1live-live.cast.addradio.de/wdr/1live/live/mp3/128/stream.mp3 -ar 48000 -c:a libfdk_aac -b:a 128k -f hls -hls_time 2 -method PUT -hls_segment_filename 'http://18.185.31.81/%v/segment_%04d.ts' -master_pl_name 'master.m3u8' -timeout 2 'http://18.185.31.81/%v/out.m3u8' -loglevel trace ffmpeg version n4.0.1 built on ubuntu 16.04
1.
https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/hlsenc.c#L277
First I thought I can just rerun „ff_http_do_new_request“ if result shows failed state
But function does NOT return any errors, if webserver returns HTTP 500.
2.
„ff_http_do_new_request“ refers to -> „http_open_cnx“
https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/http.c#L283
I thought that I can extend handling for http_code 30x for http_code 500, but function „http_open_cnx_internal“ did never return this code, though web server did (see 1.)
3.
„http_open_cnx“ refers to -> „http_open_cnx_internal“ refers to -> „http_connect“.
https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/http.c#L1311
Here this function returns ALWAYS http_code 200 for posting data.
Function „http_read_header“ will NEVER be executed.
https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/http.c#L1317
This problem happens only for the cases like:
1) Server is there and accpets the connection (handshake)
2) However, server does hve the patch to PUT the data.
On; http.c at http_connect, before ffurl_write functions, there needs to have a block to check if URL is valid.
A simple bash check:
curl -w '%{http_code}' --request PUT --url "http://176.235.14.189:9090/OTTCAHLS"/ --data
curl: (52) Empty reply from server
000
curl -w '%{http_code}' --request PUT --url "http://176.235.14.189:9090/OTTCAHLS200/" --data
500
(bash is just an example, a c code need to be written. I work on it.)
If path is not there, HTTP server returns Interal Server Error and curl reports the same.
I couldn't find a better way to handle this becuase, ffurl_write goes to avio.c and you cant access HTTPContext from there.