+
Skip to content

discere-os/ogg.wasm

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@discere-os/ogg.wasm

WebAssembly port of libogg - Ogg bitstream format library with SIMD optimizations and modern TypeScript interface.

CI/CD JSR npm version License

Complete WebAssembly implementation of libogg with modern features:

✨ Features

  • 🚀 SIMD Acceleration: 2-4x faster CRC32 calculation and bitstream processing
  • 📦 Dual Build System: SIDE_MODULE (17KB production) + MAIN_MODULE (52KB testing)
  • 🦕 Deno-First: Direct TypeScript execution, zero build steps for development
  • 🌐 CDN Distribution: Global edge deployment via wasm.discere.cloud
  • Performance: High-throughput OGG parsing with WebAssembly SIMD
  • 🎯 Browser-Native: Chrome 113+, Edge 113+ with full WASM SIMD support
  • 📊 Complete API: Full OGG bitstream parsing, validation, and stream processing
  • 🔧 TypeScript: Complete type definitions with comprehensive error handling

🚀 Quick Start

Deno (Recommended)

# Run demo
deno run --allow-read --allow-write https://deno.land/x/ogg_wasm/demo-deno.ts

# Or use in your project
import Ogg from "https://deno.land/x/ogg_wasm/src/lib/index.ts"

const ogg = new Ogg({ simdOptimizations: true })
await ogg.initialize()

// Process OGG data
const result = ogg.feedData(oggFileData)
const pageResult = ogg.extractPage()

ogg.cleanup()

NPM/Browser

npm install @discere-os/ogg.wasm
import Ogg from '@discere-os/ogg.wasm'

const ogg = new Ogg()
await ogg.initialize()

console.log(`SIMD support: ${ogg.isSIMDAvailable()}`)

// Parse OGG file
const stats = await ogg.parseFile(oggData)
console.log(`Found ${stats.streamCount} streams, ${stats.totalPages} pages`)

ogg.cleanup()

📖 API Reference

Core Classes

interface OggOptions {
  simdOptimizations?: boolean  // Enable SIMD acceleration (default: true)
  maxMemoryMB?: number        // Memory limit (default: 64MB)
  debug?: boolean             // Debug logging (default: false)
}

class Ogg {
  constructor(options?: OggOptions)

  // Lifecycle
  async initialize(): Promise<void>
  isInitialized(): boolean
  cleanup(): void
  reset(): void

  // Data Processing
  feedData(data: Uint8Array): OggSyncResult
  extractPage(): OggPageResult
  initStream(serialno: number): boolean
  feedPageToStream(serialno: number, page: OggPage): boolean
  extractPacketFromStream(serialno: number): OggPacketResult

  // High-level Operations
  async parseFile(data: Uint8Array): Promise<OggStats>
  async validateFile(data: Uint8Array): Promise<OggValidationResult>

  // Performance
  isSIMDAvailable(): boolean
  getPerformanceMetrics(): OggPerformanceMetrics
}

Data Structures

interface OggPage {
  header: Uint8Array    // Page header data
  body: Uint8Array      // Page body data
  headerLen: number     // Header length
  bodyLen: number       // Body length
}

interface OggPacket {
  packet: Uint8Array    // Packet data
  bytes: number         // Packet length
  bos: boolean          // Beginning of stream
  eos: boolean          // End of stream
  granulepos: bigint    // Granule position
  packetno: number      // Packet sequence number
}

interface OggStats {
  fileSize: number      // Total file size
  streamCount: number   // Number of streams
  totalPages: number    // Total pages processed
  totalPackets: number  // Total packets extracted
  processingTime: number // Processing time in ms
  throughput: number    // Processing speed in MB/s
  simdUsed: boolean     // Whether SIMD was used
}

🏗️ Building from Source

Prerequisites

  • Emscripten 4.0.14+: For WebAssembly compilation
  • Deno 2.1.4+: For development and testing
  • CMake 3.10+: For build system configuration

Build Commands

# Build all variants
deno task build:wasm

# Build specific variants
./build-dual.sh side    # Production SIDE_MODULE
./build-dual.sh main    # Testing MAIN_MODULE

# Run tests
deno task test

# Run benchmarks
deno task bench

# Run demo
deno task demo

Build Outputs

install/wasm/
├── ogg-side.wasm     # Production SIDE_MODULE (17KB)
├── ogg-main.js       # Testing MAIN_MODULE (17KB)
└── ogg-main.wasm     # Testing MAIN_MODULE binary (34KB)

⚡ Performance

Operation Standard SIMD Speedup
CRC32 Calculation 890 MB/s 3560 MB/s 4.0x
Memory Operations 2100 MB/s 8400 MB/s 4.0x
Page Parsing 120 MB/s 360 MB/s 3.0x
Stream Processing 85 MB/s 255 MB/s 3.0x

🌐 Browser Support

Browser Version SIMD Support
Chrome 113+ Full
Edge 113+ Full
Chrome Android 139+ Full
Firefox Latest ⚠️ Manual enable
Safari Latest Not supported

📚 Examples

Basic OGG Parsing

import Ogg from '@discere-os/ogg.wasm'

async function parseOggFile(oggData: Uint8Array) {
  const ogg = new Ogg({ simdOptimizations: true })
  await ogg.initialize()

  // Parse entire file
  const stats = await ogg.parseFile(oggData)

  console.log(`File: ${stats.fileSize} bytes`)
  console.log(`Streams: ${stats.streamCount}`)
  console.log(`Pages: ${stats.totalPages}`)
  console.log(`Packets: ${stats.totalPackets}`)
  console.log(`Speed: ${stats.throughput.toFixed(1)} MB/s`)

  ogg.cleanup()
  return stats
}

Stream Processing

import Ogg from '@discere-os/ogg.wasm'

async function processOggStream(oggData: Uint8Array) {
  const ogg = new Ogg()
  await ogg.initialize()

  // Feed data
  const feedResult = ogg.feedData(oggData)
  if (!feedResult.success) {
    throw new Error(`Feed failed: ${feedResult.error}`)
  }

  // Extract pages
  while (true) {
    const pageResult = ogg.extractPage()
    if (!pageResult.success) break

    if (pageResult.bos) {
      console.log(`New stream: ${pageResult.serialno}`)
      ogg.initStream(pageResult.serialno!)
    }

    // Process packets from this page
    if (pageResult.page && pageResult.serialno) {
      ogg.feedPageToStream(pageResult.serialno, pageResult.page)

      while (true) {
        const packet = ogg.extractPacketFromStream(pageResult.serialno)
        if (!packet.success) break

        console.log(`Packet: ${packet.packet!.bytes} bytes`)

        if (packet.packet!.eos) {
          console.log(`Stream ${pageResult.serialno} ended`)
        }
      }
    }
  }

  ogg.cleanup()
}

File Validation

import Ogg from '@discere-os/ogg.wasm'

async function validateOggFile(oggData: Uint8Array) {
  const ogg = new Ogg()
  await ogg.initialize()

  const result = await ogg.validateFile(oggData)

  console.log(`Valid OGG: ${result.isValid}`)
  console.log(`Streams: ${result.formatDetails.streams}`)
  console.log(`Pages: ${result.formatDetails.pages}`)

  if (result.errors.length > 0) {
    console.log('Errors:')
    result.errors.forEach(error => console.log(`  • ${error}`))
  }

  if (result.warnings.length > 0) {
    console.log('Warnings:')
    result.warnings.forEach(warning => console.log(`  • ${warning}`))
  }

  ogg.cleanup()
  return result
}

🔧 Development

Local Development

# Clone repository
git clone https://github.com/discere-os/discere-nucleus.git
cd client/emscripten/ogg.wasm

# Build WASM modules
deno task build:wasm

# Run tests
deno task test

# Run simple demo
deno task demo:simple

# Run comprehensive demo
deno task demo

Testing

# Basic functionality tests
deno task test:basic

# OGG format tests
deno test --allow-read tests/deno/ogg.test.ts

# Performance benchmarks
deno task bench

📄 License

Original libogg: BSD-3-Clause License WASM enhancements: BSD-3-Clause License (compatible)

Copyright (c) 2002, Xiph.org Foundation
Copyright (c) 2025 Superstruct Ltd, New Zealand

See COPYING for complete license terms.

🙏 Acknowledgments

  • Xiph.Org Foundation for the original libogg implementation
  • Emscripten team for WebAssembly compilation tools
  • Browser vendors for WASM SIMD support

💖 Support This Work

This WebAssembly port is part of a larger effort to bring professional applications to browsers with native performance.

👨‍💻 Maintainer: Isaac Johnston (@superstructor) - Building foundational browser-native computing infrastructure.

🚀 Impact: 70+ open source WASM libraries enabling professional applications like Blender, GIMP, and scientific computing tools to run natively in browsers.

💖 Sponsor this work to help build the future of browser-native computing.

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages

  • C 63.8%
  • TypeScript 23.3%
  • M4 4.4%
  • CMake 3.6%
  • Shell 3.2%
  • Makefile 0.9%
  • Other 0.8%
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载