Fixed crashes and improved weblist
parent
fcecf18276
commit
5ac06d4819
|
@ -2,6 +2,11 @@ interface CodecCostructor {
|
|||
new (codecSampleRate: number) : Codec;
|
||||
}
|
||||
|
||||
enum CodecType {
|
||||
OPUS_VOICE,
|
||||
OPUS_MUSIC
|
||||
}
|
||||
|
||||
class BufferChunk {
|
||||
buffer: AudioBuffer;
|
||||
index: number;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/// <reference path="BasicCodec.ts"/>
|
||||
|
||||
class RawCodec extends BasicCodec {
|
||||
class CodecWrapperRaw extends BasicCodec {
|
||||
converterRaw: any;
|
||||
converter: Uint8Array;
|
||||
bufferSize: number = 4096 * 4;
|
|
@ -1,15 +1,11 @@
|
|||
/// <reference path="BasicCodec.ts"/>
|
||||
|
||||
enum CodecWorkerType {
|
||||
WORKER_OPUS
|
||||
}
|
||||
|
||||
class CodecWrapper extends BasicCodec {
|
||||
class CodecWrapperWorker extends BasicCodec {
|
||||
private _worker: Worker;
|
||||
private _workerListener: {token: string, resolve: (data: any) => void}[] = [];
|
||||
private _workerCallbackToken = "callback_token";
|
||||
private _workerTokeIndex: number = 0;
|
||||
type: CodecWorkerType;
|
||||
type: CodecType;
|
||||
|
||||
private _initialized: boolean = false;
|
||||
private _workerCallbackResolve: () => any;
|
||||
|
@ -17,7 +13,7 @@ class CodecWrapper extends BasicCodec {
|
|||
|
||||
private _initializePromise: Promise<Boolean>;
|
||||
name(): string {
|
||||
return "Worker for " + CodecWorkerType[this.type] + " Channels " + this.channelCount;
|
||||
return "Worker for " + CodecType[this.type] + " Channels " + this.channelCount;
|
||||
}
|
||||
|
||||
initialise() : Promise<Boolean> {
|
||||
|
@ -131,10 +127,19 @@ class CodecWrapper extends BasicCodec {
|
|||
return true;
|
||||
}
|
||||
|
||||
constructor(type: CodecWorkerType, channelCount: number) {
|
||||
constructor(type: CodecType) {
|
||||
super(48000);
|
||||
this.type = type;
|
||||
this.channelCount = channelCount;
|
||||
switch (type) {
|
||||
case CodecType.OPUS_MUSIC:
|
||||
this.channelCount = 2;
|
||||
break;
|
||||
case CodecType.OPUS_VOICE:
|
||||
this.channelCount = 1;
|
||||
break;
|
||||
default:
|
||||
throw "invalid codec type!";
|
||||
}
|
||||
}
|
||||
|
||||
private generateToken() {
|
|
@ -187,7 +187,7 @@ function loadDebug() {
|
|||
|
||||
...custom_scripts
|
||||
]).then(() => load_wait_scripts([
|
||||
"js/codec/CodecWrapper.js"
|
||||
"js/codec/CodecWrapperWorker.js"
|
||||
])).then(() => load_wait_scripts([
|
||||
"js/main.js"
|
||||
])).then(() => {
|
||||
|
|
|
@ -130,8 +130,8 @@ class VoiceConnection {
|
|||
new CodecPool(this,1,"Spex B", undefined), //Spex
|
||||
new CodecPool(this,2,"Spex C", undefined), //Spex
|
||||
new CodecPool(this,3,"CELT Mono", undefined), //CELT Mono
|
||||
new CodecPool(this,4,"Opus Voice", () => { return new CodecWrapper(CodecWorkerType.WORKER_OPUS, 1) }), //opus voice
|
||||
new CodecPool(this,5,"Opus Music", () => { return new CodecWrapper(CodecWorkerType.WORKER_OPUS, 2) }) //opus music
|
||||
new CodecPool(this,4,"Opus Voice", () => { return audio.codec.new_instance(CodecType.OPUS_VOICE) }), //opus voice
|
||||
new CodecPool(this,5,"Opus Music", () => { return audio.codec.new_instance(CodecType.OPUS_MUSIC) }) //opus music
|
||||
];
|
||||
|
||||
private vpacketId: number = 0;
|
||||
|
|
|
@ -11,10 +11,6 @@ interface CodecWorker {
|
|||
reset();
|
||||
}
|
||||
|
||||
enum CodecWorkerType {
|
||||
WORKER_OPUS
|
||||
}
|
||||
|
||||
let codecInstance: CodecWorker;
|
||||
|
||||
onmessage = function(e: MessageEvent) {
|
||||
|
@ -27,12 +23,14 @@ onmessage = function(e: MessageEvent) {
|
|||
//console.log(prefix + " Got from main: %o", data);
|
||||
switch (data.command) {
|
||||
case "initialise":
|
||||
console.log(prefix + "Got initialize for type " + CodecWorkerType[data.type as CodecWorkerType]);
|
||||
switch (data.type as CodecWorkerType) {
|
||||
case CodecWorkerType.WORKER_OPUS:
|
||||
codecInstance = new OpusWorker(data.channelCount, data.channelCount == 1 ? OpusType.VOIP : OpusType.AUDIO);
|
||||
console.log(prefix + "Got initialize for type " + CodecType[data.type as CodecType]);
|
||||
switch (data.type as CodecType) {
|
||||
case CodecType.OPUS_MUSIC:
|
||||
codecInstance = new OpusWorker(2, OpusType.AUDIO);
|
||||
break;
|
||||
case CodecType.OPUS_VOICE:
|
||||
codecInstance = new OpusWorker(1, OpusType.VOIP);
|
||||
break;
|
||||
|
||||
default:
|
||||
res.message = "Could not find worker type!";
|
||||
console.error("Could not resolve opus type!");
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
/// <reference path="../../declarations/imports_shared.d.ts"/>
|
||||
|
||||
namespace audio.codec {
|
||||
export function new_instance(type: CodecType) : BasicCodec {
|
||||
return new CodecWrapperWorker(type);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue