-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented async pgs loading. This enables the renderer to parse the…
… subtitle stream while it's still downloading. All display sets in the completed download range can already be rendered and don't have to wait until the whole file is completed.
- Loading branch information
Showing
11 changed files
with
214 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {BinaryReader} from "./binaryReader"; | ||
|
||
export interface AsyncBinaryReader extends BinaryReader { | ||
/** | ||
* Ensures that the given number of bytes is available to read synchronously. | ||
* This will wait until the data is ready to read. | ||
* @param count The number of bytes requested. | ||
* @return Returns if the requested number of bytes could be loaded. | ||
*/ | ||
requestData(count: number): Promise<boolean>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import {AsyncBinaryReader} from "./asyncBinaryReader"; | ||
import {CombinedBinaryReader} from "./combinedBinaryReader"; | ||
|
||
/** | ||
* A binary reader based on a readable stream. This can read a partially loaded stream - for example a download. | ||
*/ | ||
export class StreamBinaryReader implements AsyncBinaryReader { | ||
private readonly stream: ReadableStreamDefaultReader<Uint8Array>; | ||
private readonly reader: CombinedBinaryReader; | ||
private $eof: boolean = false; | ||
|
||
public constructor(stream: ReadableStreamDefaultReader<Uint8Array>) { | ||
this.stream = stream; | ||
this.reader = new CombinedBinaryReader([]); | ||
} | ||
|
||
public get position(): number { | ||
return this.reader.position; | ||
} | ||
|
||
public get length(): number { | ||
return this.reader.length; | ||
} | ||
|
||
public get eof(): boolean { | ||
return this.$eof; | ||
} | ||
|
||
public readByte(): number { | ||
return this.reader.readByte(); | ||
} | ||
|
||
public readBytes(count: number): Uint8Array { | ||
return this.reader.readBytes(count); | ||
} | ||
|
||
public async requestData(count: number = 0): Promise<boolean> { | ||
// Always try to peak one byte ahead to detect end-of-file early | ||
while (this.reader.position + count + 1 > this.reader.length && !this.$eof) { | ||
let { value, done } = await this.stream.read(); | ||
|
||
if (value) { | ||
this.reader.push(value); | ||
} | ||
|
||
if (done) { | ||
this.$eof = true; | ||
} | ||
} | ||
|
||
// Returns if all data could be requested | ||
return this.reader.position + count <= this.reader.length; | ||
} | ||
} |
Oops, something went wrong.