Git Product home page Git Product logo

Comments (12)

mrcolak avatar mrcolak commented on May 11, 2024

I've made some debug.

When the video freezed, I've checked the current downloading segments and found the peerId. And when I checked Peer's downloadingSegment value, I see that its not increasing. It must be a very slow connection or upload speed etc.

After I destroy that Peer, segment downloaded from http and video continued.

photo_2018-12-06_01-18-23

So I believe that p2pSegmentDownloadTimeout is not doing its job.

from p2p-media-loader.

mrlika avatar mrlika commented on May 11, 2024

p2pSegmentDownloadTimeout represents downloading timeout or connection timeout?

It is the connection timeout (i.e. timeout for the response from the remote peer that it is willing to send us the requested segment) and not the timeout of segment data download.

Documentation should be improved.

from p2p-media-loader.

mrcolak avatar mrcolak commented on May 11, 2024

I've write some code snipped to handle this downloading timeout situation. This 5 second interval is checking active downloading segments every time and if the downloaded byte value is not change for the next tick, it will cancel that segment download process.

var peerSegmentStats = [];
window.setInterval(function() {
	engine.loader.p2pManager.peers.forEach(function(peer) {
		if(peer.downloadingSegment !== null) {
			if(peerSegmentStats[peer.downloadingSegment.id] !== peer.downloadingSegment.bytesDownloaded)
				peerSegmentStats[peer.downloadingSegment.id] = peer.downloadingSegment.bytesDownloaded;
			else {
				console.log("cancelling", peer.downloadingSegment.id ,"request from", peer.id, (peer.downloadingSegment.bytesDownloaded/1024).toFixed(2), "/", (peer.downloadingSegment.size/1024).toFixed(2));
				delete peerSegmentStats[peer.downloadingSegment.id];
				engine.loader.p2pManager.peerSegmentRequests.delete(peer.downloadingSegment.id);
				peer.cancelSegmentRequest();
			}
	    }
	});
}, 1000*5)

engine.loader.on(p2pml.core.Events.SegmentLoaded, function (segment) {
    delete peerSegmentStats[segment.id];
});

from p2p-media-loader.

mrlika avatar mrlika commented on May 11, 2024

Yes, it can be done by adding and handling additional configuration parameters.

Currently, if a remote peer is slow and failed to deliver full segment in time, the P2P download will be aborted and HTTP download initiated.

requiredSegmentsPriority configuration parameter, that is also not very well documented, is responsible for this.

requiredSegmentsPriority | Integer | 1 | The maximum priority of the segments to be downloaded (if not available) as quickly as possible (i.e. via HTTP method)

By default next 2 segments after currently playing segment, if not already downloaded over P2P, will be forced to be downloaded over HTTP.

from p2p-media-loader.

mrcolak avatar mrcolak commented on May 11, 2024

Currently, if a remote peer is slow and failed to deliver full segment in time, the P2P download will be aborted and HTTP download initiated.

What do you mean by in time Is there an option to set this time?

What I need is something like this;

If a remote peer is slow and failed to deliver full segment in 5 seconds, the P2P download will be aborted and HTTP download initiated. And It's configuring like this;
peerFailAbortTime: 5000

In my case, all segments should be downloaded at least 5 seconds. I already make this happend with the code send you above but If there is a way to do this within the library, I would like to use that for integrity.

from p2p-media-loader.

mrlika avatar mrlika commented on May 11, 2024

By default with "requiredSegmentsPriority = 1" in time means that the segment you are downloading over P2P should not become of priority 0 or 1.

Priority 0 has the segment that goes next after currently playing one. Priority 1 has the segment next after segment with priority 0.

from p2p-media-loader.

mrcolak avatar mrcolak commented on May 11, 2024

I still didn't understand how am I going to limit the segment download time within X seconds. :(

from p2p-media-loader.

mrlika avatar mrlika commented on May 11, 2024

It is not possible. And I am not sure that it should be implemented.

But when player reaches that segment, Its just freezes and waiting the segment download finish.

Checking this now. It should not happen.

from p2p-media-loader.

mrlika avatar mrlika commented on May 11, 2024

But when player reaches that segment, Its just freezes and waiting the segment download finish.

I cannot reproduce it. If a segment is loading very slow over P2P, the download will be canceled and the segment will be downloaded over HTTP.

from p2p-media-loader.

mrlika avatar mrlika commented on May 11, 2024

You can try to increase requiredSegmentsPriority or segment duration. Probably not enough time to download slow P2P segments over HTTP.

from p2p-media-loader.

mrcolak avatar mrcolak commented on May 11, 2024
var peerSegmentStats = [];
window.setInterval(function() {
	engine.loader.p2pManager.peers.forEach(function(peer) {
		if(peer.downloadingSegment !== null) {
			if(peerSegmentStats[peer.downloadingSegment.id] !== peer.downloadingSegment.bytesDownloaded)
				peerSegmentStats[peer.downloadingSegment.id] = peer.downloadingSegment.bytesDownloaded;
			else {
				console.log("cancelling", peer.downloadingSegment.id ,"request from", peer.id, (peer.downloadingSegment.bytesDownloaded/1024).toFixed(2), "/", (peer.downloadingSegment.size/1024).toFixed(2));
				delete peerSegmentStats[peer.downloadingSegment.id];
				engine.loader.p2pManager.peerSegmentRequests.delete(peer.downloadingSegment.id);
				peer.cancelSegmentRequest();
			}
	    }
	});
}, 1000*5)

engine.loader.on(p2pml.core.Events.SegmentLoaded, function (segment) {
    delete peerSegmentStats[segment.id];
});

This is working fine so we can close this case.

from p2p-media-loader.

mrcolak avatar mrcolak commented on May 11, 2024
var engine = new p2pml.hlsjs.Engine({
  loader: {
    cachedSegmentExpiration: 1000 * 60 * 60 * 2,
    cachedSegmentsCount: 800,
    simultaneousP2PDownloads: 15,
    bufferedSegmentsCount: 30,
    p2pSegmentDownloadTimeout: 5000
  }
});

With this configuration, I've managed to increase peer ratio from ~%20 to ~%50... There were no reports from users for now. So I'll try to increase these numbers a little bit if noone complain about crashes or etc.

from p2p-media-loader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.