zhaohappy / libmedia

一个 TypeScript 实现的高性能媒体库,支持 WebCodecs 和 Wasm。 A high-performance media library implemented in TypeScript, support WebCodecs and Wasm.
https://zhaohappy.github.io/libmedia/product/player/player.html
GNU Lesser General Public License v3.0
136 stars 21 forks source link

How to implement WebSocket IOLoader & How to customize IOLoader #15

Closed KunMengcode closed 2 months ago

KunMengcode commented 2 months ago

I have a WebSocket interface that transmits H265 raw streams internally. I tried to search for the WebSocket footprint but couldn't find it. Did I overlook something?

zhaohappy commented 2 months ago

WebSocket IOLoader is not yet implemented. You can refer to FileIOLoader to implement it. I think the size method and seek method of WebSocket IOLoader is not universal method.

zhaohappy commented 2 months ago

I had implemented CustomIOLoader for custom data input.

class MyIOLoader extends AVPlayer.IOLoader.CustomIOLoader {
        constructor(ws) {
          super()
          this.ws = ws
        }

        get ext() {
          return 'h265'
        }

        get name() {
          return this.ws
        }

        async open() {
           // open websocket
        }

        async read(buffer, options) {
          // write data to buffer
        }

        async seek(pos, options) {
          // seek if can
        }

        async size() {
         // return total size if has
        }

        async stop() {
          // stop ioloader
        }
}
const player = new AVPlayer();
await player.load(new MyIOLoader('wss://xxxx'));
await player.play();
KunMengcode commented 2 months ago

Yes, I also believe that WebSocket IOLoader is not a universal method. I saw in Readme that WebSocket was mentioned, and I was very confused about how WebSocket IOLoader responds to complex requirements. I am indeed something I overlooked( CustomIOLoader ),For WebSocket, Customizing IOLoader is indeed a good choice. When I couldn't find any content related to Websocket, I started modifying HlsILOoader.ts but didn't find Customizing IOLoader. ts, which is really a stupid question Thank you for the prompt.