p2p-media-loader icon indicating copy to clipboard operation
p2p-media-loader copied to clipboard

Strange error

Open jazz1611 opened this issue 11 months ago • 13 comments

Hello,

Current i'm testing again with PlayerJS with configure below

    <script type="importmap">
        {
            "imports": {
                "p2p-media-loader-core": "//cdn.jsdelivr.net/npm/p2p-media-loader-core@latest/dist/p2p-media-loader-core.es.min.js",
                "p2p-media-loader-hlsjs": "//cdn.jsdelivr.net/npm/p2p-media-loader-hlsjs@latest/dist/p2p-media-loader-hlsjs.es.min.js"
            }
        }
    </script>
<script type="module">
    
            import { HlsJsP2PEngine } from "p2p-media-loader-hlsjs";
            Hls = HlsJsP2PEngine.injectMixin(Hls);
    	var player = new Playerjs({
    	    id: "video_player",
    	    file: "link.m3u8",
    	    poster: "poster.jpg",
    	    thumbnails: "thumbnail.vtt",
    	    autoplay: 0,
    	    lang: "en",
            
            hlsconfig: {
                p2p: {
                    core: {
                        swarmId: "LqIauxxxxxxxp",
                        simultaneousHttpDownloads: 1,
                    },
                    onHlsJsCreated: (hls) => {
                        hls.p2pEngine.addEventListener("onChunkDownloaded", (bytesLength, downloadSource, peerId) => {
                            if (peerId) {
                                Downloaded += bytesLength;
                            }
                            Downloaded_Total += bytesLength;
                        });
                    },
                },
            },
    	});
</script>

due to some security and privacy reasons i cant share the stream link for testing but without using P2P everything still works fine. The previous .ts files loaded normally and then suddenly an error appeared as shown below.

Image

if i access the .ts files directly it works fine. what should i do in this case. I use HLS VOD to stream video

jazz1611 avatar Feb 20 '25 11:02 jazz1611

Does it work if comment only this line:

            // Hls = HlsJsP2PEngine.injectMixin(Hls);

mrlika avatar Feb 20 '25 12:02 mrlika

Does it work if comment only this line:

            // Hls = HlsJsP2PEngine.injectMixin(Hls);

if comment that line then player still works normally without P2P feature

ghost avatar Feb 20 '25 15:02 ghost

I have tried the configuration below and it has limited the error. When I only have 1 tab open and there are no other peers, the video is okay to watch. If I open a tab with Firefox/Chrome browser, the above error starts to occur but less frequently. Maybe my streaming server is not fast enough like CDN but if I don't use P2P feature, I watch the video smoothly and stably, almost no buffering when seek the video

core: {
	swarmId: "xxxxxxxxxx",
	highDemandTimeWindow: 60,
	simultaneousHttpDownloads: 1,
	p2pErrorRetries: 5,
	p2pNotReceivingBytesTimeoutMs: 3000,
	p2pDownloadTimeWindow: 600,
	httpErrorRetries: 10,
	httpNotReceivingBytesTimeoutMs: 10000,
	httpDownloadTimeWindow: 300,
},

ghost avatar Feb 20 '25 17:02 ghost

Hello @jazz1611,

Does the issue occur only with your specific manifest? You can try using this demo manifest instead:

"https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.ism/tears-of-steel-audio_eng=128002-video_eng=2200000.m3u8".

Please let us know if the problem persists with this stream or if it's still only occurring with your server.

Additionally, consider subscribing to the onSegmentAbort and onSegmentError events in the P2P engine (you can find more details here). This will help capture any error messages that may provide more insight into the issue.

As a further step, you can also add the following to your browser console and reload the page. This will enable you to view the logs for requests: localStorage.debug = 'p2pml-core:request-main'

DimaDemchenko avatar Feb 20 '25 20:02 DimaDemchenko

Hello @DimaDemchenko ,

with this stream link it works well with P2P feature "https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.ism/tears-of-steel-audio_eng=128002-video_eng=2200000.m3u8".

Image

but if I use the stream link from my server, the manifest contains 3 different video qualities and 3 different audio streams, the problem starts to occur example:

#EXTM3U
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",LANGUAGE="hin",NAME="Hindi",DEFAULT=YES,AUTOSELECT=YES,URI="1080/audio/0.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",LANGUAGE="eng",NAME="English",DEFAULT=NO,AUTOSELECT=YES,URI="1080/audio/1.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",LANGUAGE="jpn",NAME="Japanese",DEFAULT=NO,AUTOSELECT=YES,URI="1080/audio/2.m3u8"
#EXT-X-STREAM-INF:BANDWIDTH=629067,RESOLUTION=480x360,AUDIO="audio"
360.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1216271,RESOLUTION=1280x720,AUDIO="audio"
720.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1860628,RESOLUTION=1920x1080,AUDIO="audio"
1080.m3u8

Image Image

and as I said above, if i don't use the P2P feature, the download time of each .ts file only takes an average of 1-3 seconds, but when i use the P2P feature, the download time of the .ts file from the server increases quite a bit, from 6-15 seconds on average. my server has no connection or speed limits and has unmetered 20Gbps ports, on average it only uses 10-13 Gbps

ghost avatar Feb 21 '25 09:02 ghost

Hi @jazz1611, It would be really helpful if you could create a private demo and send it to us (my email is in my profile). This would assist us in investigating the issue more efficiently.

DimaDemchenko avatar Feb 21 '25 14:02 DimaDemchenko

Hi @jazz1611, It would be really helpful if you could create a private demo and send it to us (my email is in my profile). This would assist us in investigating the issue more efficiently.

After using the configuration below, the above error has been significantly reduced, and the P2P feature works stably.

core: {
	swarmId: "xxxxxxxxxx",
	announceTrackers: ["my-tracker", "wss://tracker.webtorrent.dev", "wss://tracker.openwebtorrent.com"],
	highDemandTimeWindow: 60,
	simultaneousHttpDownloads: 1,
// 	p2pErrorRetries: 5,
	p2pNotReceivingBytesTimeoutMs: 3000,
	p2pDownloadTimeWindow: 600,
// 	httpErrorRetries: 7,
	httpNotReceivingBytesTimeoutMs: 15000,
	httpDownloadTimeWindow: 300,
},

can you help me with sample code for current peers count?

ghost avatar Feb 24 '25 10:02 ghost

can you help me with sample code for current peers count?

It depends on what specific statistics you need. If you're interested in knowing how many peers are watching a stream, you would need to gather this information from the tracker. On the other hand, if you're looking to track how many peers are connected to a specific peer, the implementation below shows how to achieve that.

// define a set to store connected peers
const peers = new Set();

// Update the config object 
onHlsJsCreated: (hls) => {
  hls.p2pEngine.addEventListener("onPeerConnect", (params) => {
    // Since you use streams with separate main and video streams, you can filter by streamType
    // to get only main stream peers
    if (params.streamType !== "main") return;

    peers.add(params.peerId);

    console.log("Connected peers:", peers.size);
  });

  hls.p2pEngine.addEventListener("onPeerClose", (params) => {
    if (params.streamType !== "main") return;

    peers.delete(params.peerId);

    console.log("Connected peers:", peers.size);
  });
},

DimaDemchenko avatar Feb 24 '25 11:02 DimaDemchenko

@DimaDemchenko i want know have many peers are watching a videoA or videoB. how to get the peer number from tracker?

ghost avatar Feb 24 '25 11:02 ghost

@DimaDemchenko i want know have many peers are watching a videoA or videoB. how to get the peer number from tracker?

To get the number of peers watching a particular video (like videoA or videoB) from your tracker, you first need to ensure that you have a production tracker. If you don’t have one, you can use our wt-tracker. It’s capable of handling up to 40k peers on a server with just 1 vCPU and 2GB RAM.

Once your private wt-tracker is running, you can access detailed statistics by querying the /stats.json route. The response will contain information about the active swarm IDs, including their hashed swarmId values and the corresponding peer count.

DimaDemchenko avatar Feb 24 '25 12:02 DimaDemchenko

@DimaDemchenko thank you i did it. i am using the library below so that old browsers still work without giving errors due to not meeting the requirements from the P2P library. what do you think about this library

Just insert that script tag before the importmap tag, no need to change anything about the configured P2P related code. Source: https://github.com/guybedford/es-module-shims <script async src="https://cdn.jsdelivr.net/npm/[email protected]/dist/es-module-shims.min.js"></script>

ghost avatar Feb 24 '25 12:02 ghost

@mrlika @DimaDemchenko i found other problem when I use Firefox browser devtool and select iPhone as shown in the picture, the error appears in the console. It only loads the contents of the manifest file when using the P2P library, if not using the P2P library, the video still plays normally. in console log HTTP “Content-Type” of “application/vnd.apple.mpegurl” is not supported. Load of media resource https://link-video/video.m3u8 (manifest) failed. Image

ghost avatar Mar 02 '25 03:03 ghost

Media Source Extensions or Managed Media Source APIs are not supported on iPhone 12/13. That is why some players choose to run native HLS on those devices. Native HLS is application/vnd.apple.mpegurl.

However, Firefox does not support native HLS application/vnd.apple.mpegurl, which is why it fails.

mrlika avatar Mar 08 '25 23:03 mrlika