Skip to content

Commit

Permalink
chore: rebase with master
Browse files Browse the repository at this point in the history
  • Loading branch information
birme committed Mar 8, 2023
1 parent afa1a53 commit 71bdb3b
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 6 deletions.
2 changes: 2 additions & 0 deletions engine/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export interface ClosedCaptions {
export interface AudioTracks {
language: string;
name: string;
channels?: number,
codecs?: string,
default?: boolean;
}

Expand Down
15 changes: 10 additions & 5 deletions engine/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ class Session {
);
// # Case: current VOD does not have the selected track.
if (!m3u8) {
debug(`[${this._sessionId}]: [${playheadState.mediaSeqAudio + playheadState.vodMediaSeqAudio}] Request Failed for current audio manifest for ${audioGroupId}-${audioLanguage}`);
debug(`[${this._sessionId}]: [${playheadState.mediaSeqAudio + playheadState.vodMediaSeqAudio}] Request Failed for current audio manifest for ${audioGroupId}-${audioLanguage}s`);
}
debug(`[${this._sessionId}]: [${manifestMseq}][${manifestDseq}] Current audio manifest for ${audioGroupId}-${audioLanguage} requested`);
this.prevVodMediaSeq.audio = playheadState.vodMediaSeqAudio;
Expand Down Expand Up @@ -972,11 +972,12 @@ class Session {
let audioGroupId = audioGroupIds[i];
for (let j = 0; j < this._audioTracks.length; j++) {
let audioTrack = this._audioTracks[j];
const audioChannels = audioTrack.channels ? audioTrack.channels : 2; // default stereo
// Make default track if set property is true.
if (audioTrack.default) {
m3u8 += `#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="${audioGroupId}",LANGUAGE="${audioTrack.language}", NAME="${audioTrack.name}",AUTOSELECT=YES,DEFAULT=YES,CHANNELS="2",URI="master-${audioGroupId}_${audioTrack.language}.m3u8;session=${this._sessionId}"\n`;
m3u8 += `#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="${audioGroupId}",LANGUAGE="${audioTrack.language}", NAME="${audioTrack.name}",AUTOSELECT=YES,DEFAULT=YES,CHANNELS="${audioChannels}",URI="master-${audioGroupId}_${audioTrack.language}.m3u8;session=${this._sessionId}"\n`;
} else {
m3u8 += `#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="${audioGroupId}",LANGUAGE="${audioTrack.language}", NAME="${audioTrack.name}",AUTOSELECT=YES,DEFAULT=NO,CHANNELS="2",URI="master-${audioGroupId}_${audioTrack.language}.m3u8;session=${this._sessionId}"\n`;
m3u8 += `#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="${audioGroupId}",LANGUAGE="${audioTrack.language}", NAME="${audioTrack.name}",AUTOSELECT=YES,DEFAULT=NO,CHANNELS="${audioChannels}",URI="master-${audioGroupId}_${audioTrack.language}.m3u8;session=${this._sessionId}"\n`;
}
}
}
Expand All @@ -987,7 +988,12 @@ class Session {
if (this._sessionProfile) {
const sessionProfile = filter ? applyFilter(this._sessionProfile, filter) : this._sessionProfile;
sessionProfile.forEach(profile => {
m3u8 += '#EXT-X-STREAM-INF:BANDWIDTH=' + profile.bw + ',RESOLUTION=' + profile.resolution[0] + 'x' + profile.resolution[1] + ',CODECS="' + profile.codecs + '"' + (defaultAudioGroupId ? `,AUDIO="${defaultAudioGroupId}"` : '') + (hasClosedCaptions ? ',CLOSED-CAPTIONS="cc"' : '') + '\n';
// Find matching AudioGroupId based on codec
const audioGroupId = audioGroupIds.find(id => {
const audioCodec = profile.codecs.split(",")[1];
return id.match(audioCodec);
});
m3u8 += '#EXT-X-STREAM-INF:BANDWIDTH=' + profile.bw + ',RESOLUTION=' + profile.resolution[0] + 'x' + profile.resolution[1] + ',CODECS="' + profile.codecs + '"' + (audioGroupId ? `,AUDIO="${audioGroupId}"` : '') + (hasClosedCaptions ? ',CLOSED-CAPTIONS="cc"' : '') + '\n';
m3u8 += "master" + profile.bw + ".m3u8;session=" + this._sessionId + "\n";
});
} else {
Expand All @@ -996,7 +1002,6 @@ class Session {
m3u8 += "master" + profile.bw + ".m3u8;session=" + this._sessionId + "\n";
});
}

this.produceEvent({
type: 'NOW_PLAYING',
data: {
Expand Down
99 changes: 99 additions & 0 deletions server-uhd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* 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: [1280, 720], bw: 3725519, codecs: "avc1.64001F,mp4a.40.2" },
{ resolution: [1280, 720], bw: 5903428, codecs: "avc1.64001F,ac-3" }
];
}

_getAudioTracks(): AudioTracks[] {
return [
{ language: "ja", "name": "日本語", channels: 2, codecs: "mp4a.40.2", default: true },
{ language: "ja", "name": "日本語", channels: 6, codecs: "ac-3", default: true }
];
}
}

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);
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"esModuleInterop": true,
"declaration": true
},
"include": ["./server.ts", "./server-demux.ts", "./server-livemix.ts", "./engine/**/*"]
"include": ["./server.ts", "./server-demux.ts", "./server-livemix.ts", "server-uhd.ts", "./engine/**/*"]
}

0 comments on commit 71bdb3b

Please sign in to comment.