Initial working version
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
import { IGetToken } from 'strtok3/lib/core';
|
||||
/**
|
||||
* 6.2 Identification Header
|
||||
* Ref: https://theora.org/doc/Theora.pdf: 6.2 Identification Header Decode
|
||||
*/
|
||||
export interface IIdentificationHeader {
|
||||
id: string;
|
||||
vmaj: number;
|
||||
vmin: number;
|
||||
vrev: number;
|
||||
vmbw: number;
|
||||
vmbh: number;
|
||||
nombr: number;
|
||||
nqual: number;
|
||||
}
|
||||
/**
|
||||
* 6.2 Identification Header
|
||||
* Ref: https://theora.org/doc/Theora.pdf: 6.2 Identification Header Decode
|
||||
*/
|
||||
export declare const IdentificationHeader: IGetToken<IIdentificationHeader>;
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IdentificationHeader = void 0;
|
||||
const Token = require("token-types");
|
||||
/**
|
||||
* 6.2 Identification Header
|
||||
* Ref: https://theora.org/doc/Theora.pdf: 6.2 Identification Header Decode
|
||||
*/
|
||||
exports.IdentificationHeader = {
|
||||
len: 42,
|
||||
get: (buf, off) => {
|
||||
return {
|
||||
id: new Token.StringType(7, 'ascii').get(buf, off),
|
||||
vmaj: buf.readUInt8(off + 7),
|
||||
vmin: buf.readUInt8(off + 8),
|
||||
vrev: buf.readUInt8(off + 9),
|
||||
vmbw: buf.readUInt16BE(off + 10),
|
||||
vmbh: buf.readUInt16BE(off + 17),
|
||||
nombr: Token.UINT24_BE.get(buf, off + 37),
|
||||
nqual: buf.readUInt8(off + 40)
|
||||
};
|
||||
}
|
||||
};
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/// <reference types="node" />
|
||||
import { ITokenizer } from 'strtok3/lib/core';
|
||||
import { IOptions } from '../../type';
|
||||
import { INativeMetadataCollector } from '../../common/MetadataCollector';
|
||||
import * as Ogg from '../Ogg';
|
||||
/**
|
||||
* Ref:
|
||||
* https://theora.org/doc/Theora.pdf
|
||||
*/
|
||||
export declare class TheoraParser implements Ogg.IPageConsumer {
|
||||
private metadata;
|
||||
private tokenizer;
|
||||
constructor(metadata: INativeMetadataCollector, options: IOptions, tokenizer: ITokenizer);
|
||||
/**
|
||||
* Vorbis 1 parser
|
||||
* @param header Ogg Page Header
|
||||
* @param pageData Page data
|
||||
*/
|
||||
parsePage(header: Ogg.IPageHeader, pageData: Buffer): void;
|
||||
flush(): void;
|
||||
calculateDuration(header: Ogg.IPageHeader): void;
|
||||
/**
|
||||
* Parse first Theora Ogg page. the initial identification header packet
|
||||
* @param {IPageHeader} header
|
||||
* @param {Buffer} pageData
|
||||
*/
|
||||
protected parseFirstPage(header: Ogg.IPageHeader, pageData: Buffer): void;
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TheoraParser = void 0;
|
||||
const initDebug = require("debug");
|
||||
const Theora_1 = require("./Theora");
|
||||
const debug = initDebug('music-metadata:parser:ogg:theora');
|
||||
/**
|
||||
* Ref:
|
||||
* https://theora.org/doc/Theora.pdf
|
||||
*/
|
||||
class TheoraParser {
|
||||
constructor(metadata, options, tokenizer) {
|
||||
this.metadata = metadata;
|
||||
this.tokenizer = tokenizer;
|
||||
}
|
||||
/**
|
||||
* Vorbis 1 parser
|
||||
* @param header Ogg Page Header
|
||||
* @param pageData Page data
|
||||
*/
|
||||
parsePage(header, pageData) {
|
||||
if (header.headerType.firstPage) {
|
||||
this.parseFirstPage(header, pageData);
|
||||
}
|
||||
}
|
||||
flush() {
|
||||
debug('flush');
|
||||
}
|
||||
calculateDuration(header) {
|
||||
debug('duration calculation not implemented');
|
||||
}
|
||||
/**
|
||||
* Parse first Theora Ogg page. the initial identification header packet
|
||||
* @param {IPageHeader} header
|
||||
* @param {Buffer} pageData
|
||||
*/
|
||||
parseFirstPage(header, pageData) {
|
||||
debug('First Ogg/Theora page');
|
||||
this.metadata.setFormat('codec', 'Theora');
|
||||
const idHeader = Theora_1.IdentificationHeader.get(pageData, 0);
|
||||
this.metadata.setFormat('bitrate', idHeader.nombr);
|
||||
}
|
||||
}
|
||||
exports.TheoraParser = TheoraParser;
|
||||
Reference in New Issue
Block a user