2024-07-24 19:27:50 +07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const BaseDispatcher = require('./BaseDispatcher');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The class that sends video packet data to the voice connection.
|
|
|
|
|
* ```js
|
|
|
|
|
* // Obtained using:
|
|
|
|
|
* client.voice.joinChannel(channel).then(connection => {
|
|
|
|
|
* // You can play a file or a stream here:
|
|
|
|
|
* const dispatcher = connection.playVideo('/home/hydrabolt/video.mp4', { fps: 60, preset: 'ultrafast' });
|
|
|
|
|
* });
|
|
|
|
|
* ```
|
2024-07-24 19:42:12 +07:00
|
|
|
* @extends {BaseDispatcher}
|
2024-07-24 19:27:50 +07:00
|
|
|
*/
|
|
|
|
|
class VideoDispatcher extends BaseDispatcher {
|
2024-10-27 02:30:45 +07:00
|
|
|
constructor(player, highWaterMark = 12, streams, fps, payloadType) {
|
|
|
|
|
super(player, highWaterMark, payloadType, true, streams);
|
2025-03-02 18:28:47 +07:00
|
|
|
/**
|
|
|
|
|
* Video FPS
|
|
|
|
|
* @type {number}
|
|
|
|
|
*/
|
2024-07-24 19:27:50 +07:00
|
|
|
this.fps = fps;
|
2025-03-02 18:28:47 +07:00
|
|
|
|
|
|
|
|
this.mtu = 1200;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get TIMESTAMP_INC() {
|
|
|
|
|
return 90000 / this.fps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get FRAME_LENGTH() {
|
|
|
|
|
return 1000 / this.fps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the type of the dispatcher
|
|
|
|
|
* @returns {'video'}
|
|
|
|
|
*/
|
|
|
|
|
getTypeDispatcher() {
|
|
|
|
|
return 'video';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
partitionMtu(data) {
|
|
|
|
|
const out = [];
|
|
|
|
|
const dataLength = data.length;
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < dataLength; i += this.mtu) {
|
|
|
|
|
out.push(data.slice(i, i + this.mtu));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return out;
|
2024-07-24 19:27:50 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set FPS
|
|
|
|
|
* @param {number} value fps
|
|
|
|
|
*/
|
|
|
|
|
setFPSSource(value) {
|
|
|
|
|
this.fps = value;
|
|
|
|
|
}
|
2025-03-02 18:28:47 +07:00
|
|
|
|
|
|
|
|
_codecCallback() {
|
|
|
|
|
throw new Error('The _codecCallback method must be implemented');
|
|
|
|
|
}
|
2024-07-24 19:27:50 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = VideoDispatcher;
|