| 36 | } |
| 37 | |
| 38 | export class TinyH264Wrapper extends AutoDisposable { |
| 39 | readonly streamId: number; |
| 40 | |
| 41 | readonly #pictureReadyEvent = new EventEmitter<PictureReadyEventArgs>(); |
| 42 | get onPictureReady() { |
| 43 | return this.#pictureReadyEvent.event; |
| 44 | } |
| 45 | |
| 46 | constructor(streamId: number) { |
| 47 | super(); |
| 48 | |
| 49 | this.streamId = streamId; |
| 50 | this.addDisposable( |
| 51 | subscribePictureReady(streamId, this.#handlePictureReady), |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | #handlePictureReady = (e: PictureReadyEventArgs) => { |
| 56 | this.#pictureReadyEvent.fire(e); |
| 57 | }; |
| 58 | |
| 59 | feed(data: ArrayBuffer) { |
| 60 | worker!.postMessage( |
| 61 | { |
| 62 | type: "decode", |
| 63 | data: data, |
| 64 | offset: 0, |
| 65 | length: data.byteLength, |
| 66 | renderStateId: this.streamId, |
| 67 | }, |
| 68 | [data], |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | override dispose() { |
| 73 | super.dispose(); |
| 74 | worker!.postMessage({ |
| 75 | type: "release", |
| 76 | renderStateId: this.streamId, |
| 77 | }); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | interface TinyH264MessageBase { |
| 82 | type: string; |