Thanks to visit codestin.com
Credit goes to github.com

Skip to content

stream.hls: simplify discard logic in writer#4526

Merged
back-to merged 1 commit into
streamlink:masterfrom
bastimeyer:stream/hls/refactor-discard
May 13, 2022
Merged

stream.hls: simplify discard logic in writer#4526
back-to merged 1 commit into
streamlink:masterfrom
bastimeyer:stream/hls/refactor-discard

Conversation

@bastimeyer

Copy link
Copy Markdown
Member

The write-discard logic added in #4229 can be simplified by just calling urllib3.HTTPResponse.drain_conn() instead of consuming the stream iterator from requests.Response.iter_content() in an empty for-loop. urllib3 calls this method itself when performing HTTP redirections.

This PR also makes the signature of HLSStreamWriter.write consistent with SegmentedStreamWriter.write.


Here's a quick verification that it doesn't create any new TCP connections and properly releases the connection to the connection pool when HLS segments get filtered out, eg. by making TwitchHLSStreamWriter.should_filter_sequence always return True:

With drain_conn() or the old implementation

$ tshark -a 'duration:30' -f 'port 443' -Y 'tcp.flags.syn==1 && tcp.flags.ack==0' -T fields -e frame.time -e ip.dst_host 2>/dev/null
May 13, 2022 17:00:27.615616135 CEST    151.101.14.167
May 13, 2022 17:00:28.508046230 CEST    23.160.0.254
May 13, 2022 17:00:28.689492535 CEST    52.223.198.7
May 13, 2022 17:00:29.051352757 CEST    52.223.201.183
May 13, 2022 17:00:29.191059161 CEST    52.223.201.183

Without drain_conn() and without the old implementation

$ tshark -a 'duration:30' -f 'port 443' -Y 'tcp.flags.syn==1 && tcp.flags.ack==0' -T fields -e frame.time -e ip.dst_host 2>/dev/null
May 13, 2022 17:01:20.196026918 CEST    151.101.14.167
May 13, 2022 17:01:21.089844450 CEST    192.108.239.254
May 13, 2022 17:01:21.297710909 CEST    99.181.79.12
May 13, 2022 17:01:21.692344568 CEST    52.223.202.210
May 13, 2022 17:01:21.846276419 CEST    52.223.202.210
May 13, 2022 17:01:23.693087843 CEST    52.223.202.210
May 13, 2022 17:01:25.769547069 CEST    52.223.202.210
May 13, 2022 17:01:27.805652743 CEST    52.223.202.210
May 13, 2022 17:01:29.885493660 CEST    52.223.202.210
May 13, 2022 17:01:31.937590737 CEST    52.223.202.210
May 13, 2022 17:01:33.964036741 CEST    52.223.202.210
May 13, 2022 17:01:36.005161107 CEST    52.223.202.210
May 13, 2022 17:01:38.064585836 CEST    52.223.202.210
May 13, 2022 17:01:40.102203952 CEST    52.223.202.210
May 13, 2022 17:01:42.173969295 CEST    52.223.202.210
May 13, 2022 17:01:44.213172565 CEST    52.223.202.210
May 13, 2022 17:01:46.274762039 CEST    52.223.202.210
May 13, 2022 17:01:48.319835125 CEST    52.223.202.210

@back-to back-to merged commit 9e4a657 into streamlink:master May 13, 2022
@bastimeyer bastimeyer deleted the stream/hls/refactor-discard branch May 13, 2022 19:10
Billy2011 added a commit to Billy2011/streamlink-27 that referenced this pull request May 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants