|
| 1 | +/* |
| 2 | + * Reference implementation of Channel Engine library using DRM (HLS+Widevine) VOD assets. |
| 3 | + * |
| 4 | + * Playback: https://shaka-player-demo.appspot.com/demo/#audiolang=sv-SE;textlang=sv-SE;uilang=sv-SE;asset=http://localhost:8000/channels/1/master.m3u8;license=https://cwip-shaka-proxy.appspot.com/no_auth;panel=CUSTOM%20CONTENT;build=uncompiled |
| 5 | + */ |
| 6 | + |
| 7 | +import { |
| 8 | + ChannelEngine, |
| 9 | + ChannelEngineOpts, |
| 10 | + IAssetManager, |
| 11 | + IChannelManager, |
| 12 | + VodRequest, |
| 13 | + VodResponse, |
| 14 | + Channel, |
| 15 | + ChannelProfile, |
| 16 | + AudioTracks, |
| 17 | +} from "./index"; |
| 18 | + |
| 19 | +class RefAssetManager implements IAssetManager { |
| 20 | + private assets; |
| 21 | + private pos; |
| 22 | + constructor(opts?) { |
| 23 | + this.assets = { |
| 24 | + 1: [ |
| 25 | + { |
| 26 | + id: 1, |
| 27 | + title: "Angel One DRM", |
| 28 | + uri: "https://storage.googleapis.com/shaka-demo-assets/angel-one-widevine-hls/hls.m3u8", |
| 29 | + // license url: https://cwip-shaka-proxy.appspot.com/no_auth |
| 30 | + }, |
| 31 | + { |
| 32 | + id: 2, |
| 33 | + title: "Angel One DRM", |
| 34 | + uri: "https://storage.googleapis.com/shaka-demo-assets/angel-one-widevine-hls/hls.m3u8", |
| 35 | + // license url: https://cwip-shaka-proxy.appspot.com/no_auth |
| 36 | + }, |
| 37 | + { |
| 38 | + id: 3, |
| 39 | + title: "BBB No DRM", |
| 40 | + uri: "https://storage.googleapis.com/shaka-demo-assets/bbb-dark-truths-hls/hls.m3u8" |
| 41 | + } |
| 42 | + ], |
| 43 | + }; |
| 44 | + this.pos = { |
| 45 | + 1: 0, |
| 46 | + }; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * |
| 51 | + * @param {Object} vodRequest |
| 52 | + * { |
| 53 | + * sessionId, |
| 54 | + * category, |
| 55 | + * playlistId |
| 56 | + * } |
| 57 | + */ |
| 58 | + getNextVod(vodRequest: VodRequest): Promise<VodResponse> { |
| 59 | + return new Promise((resolve, reject) => { |
| 60 | + const channelId = vodRequest.playlistId; |
| 61 | + if (this.assets[channelId]) { |
| 62 | + let vod: VodResponse = this.assets[channelId][this.pos[channelId]++]; |
| 63 | + if (this.pos[channelId] > this.assets[channelId].length - 1) { |
| 64 | + this.pos[channelId] = 0; |
| 65 | + } |
| 66 | + resolve(vod); |
| 67 | + } else { |
| 68 | + reject("Invalid channelId provided"); |
| 69 | + } |
| 70 | + }); |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +class RefChannelManager implements IChannelManager { |
| 75 | + getChannels(): Channel[] { |
| 76 | + return [{ id: "1", profile: this._getProfile(), audioTracks: this._getAudioTracks() }]; |
| 77 | + } |
| 78 | + |
| 79 | + _getProfile(): ChannelProfile[] { |
| 80 | + return [ |
| 81 | + { |
| 82 | + bw: 7934000, |
| 83 | + codecs: "avc1.4d001f,mp4a.40.2", |
| 84 | + resolution: [2880, 1440], |
| 85 | + }, |
| 86 | + { |
| 87 | + bw: 7514000, |
| 88 | + codecs: "avc1.4d001f,mp4a.40.2", |
| 89 | + resolution: [1920, 1080], |
| 90 | + }, |
| 91 | + { bw: 7134000, codecs: "avc1.4d001f,mp4a.40.2", resolution: [1280, 720] }, |
| 92 | + { bw: 6134000, codecs: "avc1.4d001f,mp4a.40.2", resolution: [1024, 458] }, |
| 93 | + { bw: 2323000, codecs: "avc1.4d001f,mp4a.40.2", resolution: [640, 286] }, |
| 94 | + { bw: 495894, codecs: "avc1.4d001f,mp4a.40.2", resolution: [480, 214] }, |
| 95 | + ]; |
| 96 | + } |
| 97 | + _getAudioTracks(): AudioTracks[] { |
| 98 | + return [ |
| 99 | + { language: "en", name: "English" }, |
| 100 | + ]; |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +const refAssetManager = new RefAssetManager(); |
| 105 | +const refChannelManager = new RefChannelManager(); |
| 106 | + |
| 107 | +const engineOptions: ChannelEngineOpts = { |
| 108 | + heartbeat: "/", |
| 109 | + averageSegmentDuration: 4000, |
| 110 | + channelManager: refChannelManager, |
| 111 | + defaultSlateUri: "https://maitv-vod.lab.eyevinn.technology/slate-consuo.mp4/master.m3u8", |
| 112 | + slateRepetitions: 10, |
| 113 | + redisUrl: process.env.REDIS_URL, |
| 114 | + useDemuxedAudio: true, |
| 115 | + alwaysNewSegments: true, |
| 116 | +}; |
| 117 | + |
| 118 | +const engine = new ChannelEngine(refAssetManager, engineOptions); |
| 119 | +engine.start(); |
| 120 | +engine.listen(process.env.PORT || 8000); |
0 commit comments