-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for catalog in common catalog format #103
Changes from 2 commits
0215993
a35dc11
f20a5fc
90482cf
7baad29
33b3834
3f9e9d7
d536d3b
d678d5d
485a1d6
b8d5a80
5d7a726
511ad99
eb1536a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -21,6 +21,7 @@ export class Catalog { | |||||
const str = decoder.decode(raw) | ||||||
|
||||||
try { | ||||||
if (typeof JSON.parse(str).packaging !== "string") throw new Error("invalid catalog") | ||||||
this.tracks = JSON.parse(str).tracks | ||||||
if (!isCatalog(this)) { | ||||||
throw new Error("invalid catalog") | ||||||
|
@@ -60,63 +61,68 @@ export function isCatalog(catalog: any): catalog is Catalog { | |||||
} | ||||||
|
||||||
export interface Track { | ||||||
kind: string | ||||||
container: string | ||||||
name: string | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a few other fields that should be defined here, basically anything with Location = T. Unfortunately some of these fields will be optional and default to the value in the root. ex. let packaging = catalog.tracks[0].packaging ?? catalog.packing; I think we should automatically populate the track using the default values so you don't have to perform the above every time. But that can be a future PR. |
||||||
} | ||||||
|
||||||
export interface Mp4Track extends Track { | ||||||
container: "mp4" | ||||||
init_track: string | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed |
||||||
data_track: string | ||||||
} | ||||||
|
||||||
export interface AudioTrack extends Track { | ||||||
kind: "audio" | ||||||
codec: string | ||||||
channel_count: number | ||||||
sample_rate: number | ||||||
sample_size: number | ||||||
export interface SelectionParamsVideo { | ||||||
codec: string; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed |
||||||
height: number; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
width: number; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed |
||||||
frame_rate: number | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed |
||||||
bit_rate?: number | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed |
||||||
} | ||||||
|
||||||
export interface SelectionParamsAudio { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically, the draft doesn't distinguish between audio/video types but it definitely should. |
||||||
bit_rate: number; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed |
||||||
channel_count: number; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed |
||||||
codec: string; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed |
||||||
sample_rate: number; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed |
||||||
sample_size: number; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't exist? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed |
||||||
} | ||||||
|
||||||
|
||||||
export interface AudioTrack extends Track { | ||||||
name: "audio" | ||||||
selectionParams: SelectionParamsAudio; | ||||||
} | ||||||
|
||||||
export interface VideoTrack extends Track { | ||||||
kind: "video" | ||||||
codec: string | ||||||
width: number | ||||||
height: number | ||||||
frame_rate: number | ||||||
bit_rate?: number | ||||||
name: "video" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the track name, not the kind. We can't use There's no equivalent to |
||||||
selectionParams: SelectionParamsVideo; | ||||||
} | ||||||
|
||||||
export function isTrack(track: any): track is Track { | ||||||
if (typeof track.kind !== "string") return false | ||||||
if (typeof track.container !== "string") return false | ||||||
if (typeof track.name !== "string") return false | ||||||
return true | ||||||
} | ||||||
|
||||||
export function isMp4Track(track: any): track is Mp4Track { | ||||||
if (track.container !== "mp4") return false | ||||||
if (typeof track.init_track !== "string") return false | ||||||
if (typeof track.data_track !== "string") return false | ||||||
if (!isTrack(track)) return false | ||||||
return true | ||||||
} | ||||||
|
||||||
export function isVideoTrack(track: any): track is VideoTrack { | ||||||
if (track.kind !== "video") return false | ||||||
if (typeof track.codec !== "string") return false | ||||||
if (typeof track.width !== "number") return false | ||||||
if (typeof track.height !== "number") return false | ||||||
if (!(track.name.toLowerCase().includes("video"))) return false | ||||||
if (typeof track.selectionParams.codec !== "string") return false | ||||||
if (typeof track.selectionParams.width !== "number") return false | ||||||
if (typeof track.selectionParams.height !== "number") return false | ||||||
if (!isTrack(track)) return false | ||||||
return true | ||||||
} | ||||||
|
||||||
export function isAudioTrack(track: any): track is AudioTrack { | ||||||
if (track.kind !== "audio") return false | ||||||
if (typeof track.codec !== "string") return false | ||||||
if (typeof track.channel_count !== "number") return false | ||||||
if (typeof track.sample_rate !== "number") return false | ||||||
if (typeof track.sample_size !== "number") return false | ||||||
if (!(track.name.toLowerCase().includes("audio"))) return false | ||||||
if (typeof track.selectionParams.codec !== "string") return false | ||||||
if (typeof track.selectionParams.channel_count !== "number") return false | ||||||
if (typeof track.selectionParams.sample_rate !== "number") return false | ||||||
if (typeof track.selectionParams.sample_size !== "number") return false | ||||||
if (!isTrack(track)) return false | ||||||
return true | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,8 +100,8 @@ export class Player { | |
} | ||
|
||
async #runTrack(track: Mp4Track) { | ||
if (track.kind !== "audio" && track.kind !== "video") { | ||
throw new Error(`unknown track kind: ${track.kind}`) | ||
if (!(track.name.toLowerCase().includes("audio")) && !(track.name.toLowerCase().includes("video"))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed |
||
throw new Error(`unknown track name: ${track.name}`) | ||
} | ||
|
||
const sub = await this.#connection.subscribe(this.#catalog.namespace, track.data_track) | ||
|
@@ -118,7 +118,7 @@ export class Player { | |
|
||
this.#backend.segment({ | ||
init: track.init_track, | ||
kind: track.kind, | ||
kind: track.name, | ||
header: segment.header, | ||
buffer, | ||
stream, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will JSON parse the catalog twice. Also the
isCatalog
function should perform this check.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO
Catalog
should be an interface now that there's actually stuff in the root.It means you'll need to move the other functions into the root but that's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed