-
Notifications
You must be signed in to change notification settings - Fork 27
/
multicodec.ts
104 lines (94 loc) · 2.83 KB
/
multicodec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Reference implementation of Channel Engine library
*/
import { ChannelEngine, ChannelEngineOpts,
IAssetManager, IChannelManager,
VodRequest, VodResponse, Channel, ChannelProfile,
AudioTracks
} from "../index";
class RefAssetManager implements IAssetManager {
private assets;
private pos;
constructor(opts?) {
this.assets = {
1: [
{
id: 1,
title: "Sollevante",
uri: "https://testcontent.eyevinn.technology/dolby/index.m3u8",
}
],
};
this.pos = {
1: 0,
};
}
/**
*
* @param {Object} vodRequest
* {
* sessionId,
* category,
* playlistId
* }
*/
getNextVod(vodRequest: VodRequest): Promise<VodResponse> {
console.log(this.assets);
return new Promise((resolve, reject) => {
const channelId = vodRequest.playlistId;
if (this.assets[channelId]) {
let vod = this.assets[channelId][this.pos[channelId]++];
if (this.pos[channelId] > this.assets[channelId].length - 1) {
this.pos[channelId] = 0;
}
const vodResponse = {
id: vod.id,
title: vod.title,
uri: vod.uri,
};
resolve(vodResponse);
} else {
reject("Invalid channelId provided");
}
});
}
}
class RefChannelManager implements IChannelManager {
getChannels(): Channel[] {
//return [ { id: '1', profile: this._getProfile() }, { id: 'faulty', profile: this._getProfile() } ];
return [{
id: "1",
profile: this._getProfile(),
audioTracks: this._getAudioTracks(),
}];
}
_getProfile(): ChannelProfile[] {
return [
{ resolution: [640, 360], bw: 3663471, codecs: "avc1.64001F,mp4a.40.2", channels: "2" },
{ resolution: [1280, 720], bw: 5841380, codecs: "avc1.64001F,mp4a.40.2", channels: "2" },
{ resolution: [1920, 1080], bw: 8973571, codecs: "avc1.64001F,mp4a.40.2", channels: "2" },
{ resolution: [640, 360], bw: 4301519, codecs: "avc1.64001F,ec-3", channels: "16/JOC" },
{ resolution: [1280, 720], bw: 6479428, codecs: "avc1.64001F,ec-3", channels: "16/JOC" },
{ resolution: [1920, 1080], bw: 9611619, codecs: "avc1.640032,ec-3", channels: "16/JOC" },
];
}
_getAudioTracks(): AudioTracks[] {
return [
{ language: "ja", "name": "日本語", default: true },
{ language: "en", "name": "English", default: false }
];
}
}
const refAssetManager = new RefAssetManager();
const refChannelManager = new RefChannelManager();
const engineOptions: ChannelEngineOpts = {
heartbeat: "/",
useDemuxedAudio: true,
averageSegmentDuration: 2000,
channelManager: refChannelManager,
slateRepetitions: 10,
redisUrl: process.env.REDIS_URL,
};
const engine = new ChannelEngine(refAssetManager, engineOptions);
engine.start();
engine.listen(process.env.PORT || 8000);