Home /Modules/video/video-codec-pipeline.sleela

video-codec-pipeline.sleela

lib/video/video-codec-pipeline.sleela · 164 line(s) · sleela

#sleela 2.5
material;
< video-codec-pipeline.sleela -- the self-contained, runnable build of the >
< SLeeLa video codec Controller/Verifier/Processor pipeline, parallel to the >
< audio codecs/codec-pipeline.sleela. The split per-class files >
< (VideoCodecController / VideoCodecLoader / VideoCodecVerifier / >
< VideoCodecProcessor) are the package discovery surface; this file is the >
< executable counterpart, inlining the collaborators plus a `main` that drives >
< them the way a GUI or app would. >
<  >
< Video codec ids mirror sleela_video_codec_id: >
< 0 RAW 1 H264 2 HEVC 3 AV1 4 VP8 5 VP9 6 MPEG2 7 THEORA 8 MJPEG 9 FFV1 >
< 10 PRORES 11 DNX. Result codes: 0 ok -1 unsupported -2 invalid -3 format >
< -4 io -5 not-loaded. >
<  >
< Syntax 1.11: method calls resolve on class-typed fields, so the Controller >
< holds its Verifier and Processor as fields (wired in create()) and delegates >
< through them -- a GUI drives one object: ctrl.decode(id), ctrl.resolve >
< Extension(ext), ctrl.resultText(code). >

class Verifier {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 10962;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-10";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }
  int resolveExtension(string ext) {
    if (ext == ".yuv" || ext == ".rgb") { return 0; }
    if (ext == ".h264" || ext == ".264") { return 1; }
    if (ext == ".h265" || ext == ".hevc") { return 2; }
    if (ext == ".av1") { return 3; }
    if (ext == ".mov") { return 10; }
    if (ext == ".mxf") { return 11; }
    return -1;
  }
  string resultText(int code) {
    if (code == 0) { return "ok"; }
    if (code == -1) { return "unsupported (backend not present)"; }
    if (code == -2) { return "invalid arguments"; }
    if (code == -3) { return "input is not this codec's format"; }
    if (code == -4) { return "I/O or allocation failure"; }
    if (code == -5) { return "codec not loaded"; }
    return "unknown";
  }
}

class Processor {
  int decode(boolean loaded, boolean nativeCodec, boolean backendReady) {
    if (!loaded) { return -5; }
    if (nativeCodec) { return 0; }
    if (backendReady) { return 0; }
    return -1;
  }
  int encode(boolean loaded, boolean nativeCodec, boolean backendReady) {
    if (!loaded) { return -5; }
    if (nativeCodec) { return 0; }
    if (backendReady) { return 0; }
    return -1;
  }
}

class Controller {
  int[] loaded;
  int[] backend;
  < wired by create(), called via the field (1.11) >
  Verifier verifier;
  Processor processor;

  void create() {
    loaded = new int[12];
    backend = new int[12];
    verifier = new Verifier();
    processor = new Processor();
  }

  int count() { return 12; }
  boolean isNative(int id) { return id == 0; }
  string nameOf(int id) {
    if (id == 0) { return "Raw Video"; }
    if (id == 1) { return "H.264/AVC"; }
    if (id == 3) { return "AV1"; }
    if (id == 10) { return "Apple ProRes"; }
    return "codec#" + id;
  }
  int load(int id) { loaded[id] = 1; return 0; }
  boolean isLoaded(int id) { return loaded[id] == 1; }
  void unloadAll() { int i = 0; while (i < 12) { loaded[i] = 0; i = i + 1; } }
  int registerBackend(int id) { backend[id] = 1; return 0; }
  boolean hasBackend(int id) { return backend[id] == 1; }
  int loadedCount() {
    int n = 0; int i = 0;
    while (i < 12) { if (loaded[i] == 1) { n = n + 1; } i = i + 1; }
    return n;
  }

  < Clean facade methods: delegate to the wired collaborators. >
  int resolveExtension(string ext) { return verifier.resolveExtension(ext); }
  string resultText(int code) { return verifier.resultText(code); }
  int decode(int id) { return processor.decode(isLoaded(id), isNative(id), hasBackend(id)); }
  int encode(int id) { return processor.encode(isLoaded(id), isNative(id), hasBackend(id)); }

  void main() {
    print("=== SLeeLa video codec pipeline (Controller/Loader/Verifier/Processor) ===");
    create();
    print("video codecs known: " + count());

    int raw = resolveExtension(".yuv");
    int av1 = resolveExtension(".av1");
    print("resolve .yuv -> " + raw + " (" + nameOf(raw) + ")");
    print("resolve .av1 -> " + av1 + " (" + nameOf(av1) + ")");

    print("decode .av1 before load: " + resultText(decode(av1)));

    load(raw);
    print("decode raw loaded (native): " + resultText(decode(raw)));

    load(av1);
    print("decode .av1 no backend: " + resultText(decode(av1)));
    registerBackend(av1);
    print("decode .av1 backend:    " + resultText(decode(av1)));

    print("loaded count=" + loadedCount());
    unloadAll();
    print("after unloadAll, raw loaded? " + isLoaded(raw));
    print("done");
  }
}