|
| 1 | +/* eslint-disable */ |
| 2 | +// The contents of this file below the line are copied from |
| 3 | +// @types/dom-mediacapture-transform, which is inlined here into Element Call so |
| 4 | +// that we can apply the patch to @types/dom-webcodecs found in |
| 5 | +// ./dom-webcodecs.d.ts, which it depends on. |
| 6 | +// (https://github.com/DefinitelyTyped/DefinitelyTyped/pull/72625) |
| 7 | +// Once that PR is merged and released, we can remove this file and return to |
| 8 | +// depending on @types/dom-mediacapture-transform. |
| 9 | +// ----------------------------------------------------------------------------- |
| 10 | + |
| 11 | +// In general, these types are only available behind a command line flag or an origin trial in |
| 12 | +// Chrome 90+. |
| 13 | + |
| 14 | +// This API depends on WebCodecs. |
| 15 | + |
| 16 | +// Versioning: |
| 17 | +// Until the above-mentioned spec is finalized, the major version number is 0. Although not |
| 18 | +// necessary for version 0, consider incrementing the minor version number for breaking changes. |
| 19 | + |
| 20 | +// The following modify existing DOM types to allow defining type-safe APIs on audio and video tracks. |
| 21 | + |
| 22 | +/** Specialize MediaStreamTrack so that we can refer specifically to an audio track. */ |
| 23 | +interface MediaStreamAudioTrack extends MediaStreamTrack { |
| 24 | + readonly kind: "audio"; |
| 25 | + clone(): MediaStreamAudioTrack; |
| 26 | +} |
| 27 | + |
| 28 | +/** Specialize MediaStreamTrack so that we can refer specifically to a video track. */ |
| 29 | +interface MediaStreamVideoTrack extends MediaStreamTrack { |
| 30 | + readonly kind: "video"; |
| 31 | + clone(): MediaStreamVideoTrack; |
| 32 | +} |
| 33 | + |
| 34 | +/** Assert that getAudioTracks and getVideoTracks return the tracks with the appropriate kind. */ |
| 35 | +interface MediaStream { |
| 36 | + getAudioTracks(): MediaStreamAudioTrack[]; |
| 37 | + getVideoTracks(): MediaStreamVideoTrack[]; |
| 38 | +} |
| 39 | + |
| 40 | +// The following were originally generated from the spec using |
| 41 | +// https://github.com/microsoft/TypeScript-DOM-lib-generator, then heavily modified. |
| 42 | + |
| 43 | +/** |
| 44 | + * A track sink that is capable of exposing the unencoded frames from the track to a |
| 45 | + * ReadableStream, and exposes a control channel for signals going in the oppposite direction. |
| 46 | + */ |
| 47 | +interface MediaStreamTrackProcessor<T extends AudioData | VideoFrame> { |
| 48 | + /** |
| 49 | + * Allows reading the frames flowing through the MediaStreamTrack provided to the constructor. |
| 50 | + */ |
| 51 | + readonly readable: ReadableStream<T>; |
| 52 | + /** Allows sending control signals to the MediaStreamTrack provided to the constructor. */ |
| 53 | + readonly writableControl: WritableStream<MediaStreamTrackSignal>; |
| 54 | +} |
| 55 | + |
| 56 | +declare var MediaStreamTrackProcessor: { |
| 57 | + prototype: MediaStreamTrackProcessor<any>; |
| 58 | + |
| 59 | + /** Constructor overrides based on the type of track. */ |
| 60 | + new ( |
| 61 | + init: MediaStreamTrackProcessorInit & { track: MediaStreamAudioTrack }, |
| 62 | + ): MediaStreamTrackProcessor<AudioData>; |
| 63 | + new ( |
| 64 | + init: MediaStreamTrackProcessorInit & { track: MediaStreamVideoTrack }, |
| 65 | + ): MediaStreamTrackProcessor<VideoFrame>; |
| 66 | +}; |
| 67 | + |
| 68 | +interface MediaStreamTrackProcessorInit { |
| 69 | + track: MediaStreamTrack; |
| 70 | + /** |
| 71 | + * If media frames are not read from MediaStreamTrackProcessor.readable quickly enough, the |
| 72 | + * MediaStreamTrackProcessor will internally buffer up to maxBufferSize of the frames produced |
| 73 | + * by the track. If the internal buffer is full, each time the track produces a new frame, the |
| 74 | + * oldest frame in the buffer will be dropped and the new frame will be added to the buffer. |
| 75 | + */ |
| 76 | + maxBufferSize?: number | undefined; |
| 77 | +} |
| 78 | + |
| 79 | +/** |
| 80 | + * Takes video frames as input, and emits control signals that result from subsequent processing. |
| 81 | + */ |
| 82 | +interface MediaStreamTrackGenerator<T extends AudioData | VideoFrame> |
| 83 | + extends MediaStreamTrack { |
| 84 | + /** |
| 85 | + * Allows writing media frames to the MediaStreamTrackGenerator, which is itself a |
| 86 | + * MediaStreamTrack. When a frame is written to writable, the frame’s close() method is |
| 87 | + * automatically invoked, so that its internal resources are no longer accessible from |
| 88 | + * JavaScript. |
| 89 | + */ |
| 90 | + readonly writable: WritableStream<T>; |
| 91 | + /** |
| 92 | + * Allows reading control signals sent from any sinks connected to the |
| 93 | + * MediaStreamTrackGenerator. |
| 94 | + */ |
| 95 | + readonly readableControl: ReadableStream<MediaStreamTrackSignal>; |
| 96 | +} |
| 97 | + |
| 98 | +type MediaStreamAudioTrackGenerator = MediaStreamTrackGenerator<AudioData> & |
| 99 | + MediaStreamAudioTrack; |
| 100 | +type MediaStreamVideoTrackGenerator = MediaStreamTrackGenerator<VideoFrame> & |
| 101 | + MediaStreamVideoTrack; |
| 102 | + |
| 103 | +declare var MediaStreamTrackGenerator: { |
| 104 | + prototype: MediaStreamTrackGenerator<any>; |
| 105 | + |
| 106 | + /** Constructor overrides based on the type of track. */ |
| 107 | + new ( |
| 108 | + init: MediaStreamTrackGeneratorInit & { |
| 109 | + kind: "audio"; |
| 110 | + signalTarget?: MediaStreamAudioTrack | undefined; |
| 111 | + }, |
| 112 | + ): MediaStreamAudioTrackGenerator; |
| 113 | + new ( |
| 114 | + init: MediaStreamTrackGeneratorInit & { |
| 115 | + kind: "video"; |
| 116 | + signalTarget?: MediaStreamVideoTrack | undefined; |
| 117 | + }, |
| 118 | + ): MediaStreamVideoTrackGenerator; |
| 119 | +}; |
| 120 | + |
| 121 | +interface MediaStreamTrackGeneratorInit { |
| 122 | + kind: MediaStreamTrackGeneratorKind; |
| 123 | + /** |
| 124 | + * (Optional) track to which the MediaStreamTrackGenerator will automatically forward control |
| 125 | + * signals. If signalTarget is provided and signalTarget.kind and kind do not match, the |
| 126 | + * MediaStreamTrackGenerator’s constructor will raise an exception. |
| 127 | + */ |
| 128 | + signalTarget?: MediaStreamTrack | undefined; |
| 129 | +} |
| 130 | + |
| 131 | +type MediaStreamTrackGeneratorKind = "audio" | "video"; |
| 132 | + |
| 133 | +type MediaStreamTrackSignalType = "request-frame"; |
| 134 | + |
| 135 | +interface MediaStreamTrackSignal { |
| 136 | + signalType: MediaStreamTrackSignalType; |
| 137 | +} |
0 commit comments