-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
133 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import type {Buffer} from "buffer"; | ||
import type {BoxHeader, FourCC, FullBox} from "@isomp4/core"; | ||
import {FullBoxEncoding} from "@isomp4/core"; | ||
import {readString} from "@isomp4/core/src/BufferUtils"; | ||
|
||
export interface HandlerBox extends FullBox { | ||
|
||
/** | ||
* The type of media handler for the track. | ||
* | ||
* Common types: | ||
* * `vide` | ||
* * `soun` | ||
* * `auxv` | ||
* * `meta` | ||
* * `hint` | ||
* * `text` | ||
* * `subt` | ||
* * `fdsm` | ||
*/ | ||
handlerType: "vide" | "soun" | "auxv" | "meta" | "hint" | "text" | "subt" | "fdsm" | FourCC; | ||
|
||
/** | ||
* A human-readable name for the track type. | ||
*/ | ||
name: string; | ||
|
||
} | ||
|
||
class HandlerBoxEncoding extends FullBoxEncoding { | ||
|
||
constructor() { | ||
super("hdlr"); | ||
} | ||
|
||
public override encodingLength(obj: HandlerBox): number { | ||
return super.encodingLength(obj); // TODO implement | ||
} | ||
|
||
public override encodeTo(obj: HandlerBox, buffer: Buffer): number { | ||
const requiredBytes = super.encodeTo(obj, buffer); | ||
if (requiredBytes > 0) { | ||
return requiredBytes; | ||
} | ||
// let offset = this.encodedBytes; | ||
// // TODO implementing encoding | ||
// this.encodedBytes = offset; | ||
return 0; | ||
} | ||
|
||
public override decode(buffer: Buffer, header?: BoxHeader): HandlerBox | number { | ||
const superBox = super.decode(buffer, header); | ||
if (typeof superBox === "number") { | ||
return superBox; | ||
} | ||
let offset: number = this.decodedBytes; | ||
// Assume there are no child boxes of hdlr | ||
const end: number = HandlerBoxEncoding.end(superBox, header); | ||
if (buffer.length < end) { | ||
return end; | ||
} | ||
offset += 4; // pre_defined = 0 | ||
const handlerType: FourCC = buffer.toString("binary", offset, offset += 4); | ||
offset += 12; // reserved = 0 | ||
const name: string | number = readString(buffer, offset); | ||
if (typeof name === "number") { | ||
return offset + name; | ||
} | ||
offset += readString.decodedBytes; | ||
this.decodedBytes = offset; | ||
return { | ||
...superBox, | ||
handlerType, | ||
name, | ||
}; | ||
} | ||
|
||
} | ||
|
||
export const hdlr = new HandlerBoxEncoding(); |
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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import {BoxEncoding} from "@isomp4/core"; | ||
import {hdlr} from "./hdlr.js"; | ||
import {mvhd} from "./mvhd.js"; | ||
import {stsd} from "./stsd.js"; | ||
|
||
export const stbl = new BoxEncoding("stbl", stsd); | ||
export const minf = new BoxEncoding("minf", stbl); | ||
export const mdia = new BoxEncoding("mdia", minf); | ||
export const mdia = new BoxEncoding("mdia", hdlr, minf); | ||
export const trak = new BoxEncoding("trak", mdia); | ||
export const moov = new BoxEncoding("moov", mvhd, trak); | ||
|
||
export * from "./hdlr.js"; | ||
export * from "./mvhd.js"; | ||
export * from "./samples/avc.js"; | ||
export * from "./stsd.js"; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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