Home /Modules/codecs/SLCodecController.sleela

SLCodecController.sleela

lib/codecs/SLCodecController.sleela · 126 line(s) · sleela

<< lib/codecs/SLCodecController.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines the SLeeLa standard-library type SLCodecController used within the codecs library family. >>
#sleela 2.5
material;
< Family: codecs. The SLeeLa-facing Codec Management Controller — the single >
< surface a GUI or application drives to use codecs, mirroring the native >
< "Codec Loader / Unloader / Management Controller" >
< (codecs/include/sleela_codec_manager.h). The Controller owns each codec's >
< loaded/unloaded lifecycle and the backend-registration table, and cooperates >
< with the sibling classes: >
<  >
< * SLCodecLoader    — classification (nameOf / isNative) and the standalone >
< plugin-load contract; >
< * SLCodecVerifier  — extension/magic resolution and result-code text; >
< * SLCodecProcessor — the standalone decode/encode dispatch contract. >
<  >
< As of syntax 1.11 the Controller holds its collaborators as fields and calls >
< through them directly (method calls resolve on class-typed fields). create() >
< wires an SLCodecVerifier; the Controller keeps its own lifecycle state in >
< int[] tables. >
<  >
< Codec ids mirror sleela_codec_id (0-based, registry order): >
< 0 PCM_WAV  1 AIFF  2 FLAC  3 ALAC  4 MP3  5 AAC  6 HE_AAC  7 VORBIS >
< 8 OPUS  9 SPEEX  10 WMA  11 AC3  12 EAC3  13 AMR_NB  14 AMR_WB >
< 15 G711_MULAW  16 G711_ALAW  17 MIDI  18 MATROSKA_AUDIO  19 WEBM_AUDIO >
<  >
< Handler states: 0 native, 1 backend, 2 recognized, 3 container, 4 event. >
< Result codes (sleela_codec_result): 0 ok, -1 unsupported, -2 invalid, >
< -3 format, -4 io, -5 state(not loaded). >
< As of the common-standard refactor this Controller EXTENDS the shared >
< lib/core/SLPluginService harness: the registry lifecycle (load/unload/ >
< isLoaded/loadedCount/validId/registerBackend/clearBackend/hasBackend/ >
< canProcess) and the dispatch gate (dispatchCode) are inherited and no longer >
< duplicated here. This class keeps only what is specific to codecs: the 20- >
< handler count and native-id mask (wired in create()), the Verifier it owns >
< for extension/magic resolution, and the domain verbs decode()/encode(). >
class SLCodecController extends SLPluginService {
  < ---- 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 = 10872;
  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; }

  < The verification collaborator, wired by create() and called via the field. >
  < (The loaded/backend lifecycle tables and the ready flag are inherited from >
  < SLPluginService; only the codec-specific Verifier lives here.) >
  SLCodecVerifier verifier;

  < ---- lifecycle of the controller itself ----------------------------- >

  < Build the controller with every codec registered but none loaded. Mirrors >
  < sleela_codec_manager_create. configure() (inherited) allocates the 20-entry >
  < lifecycle tables and records the native-id mask; then wire the Verifier. >
  < Native codecs encode/decode in-package: PCM/WAV (0), AIFF (1), G.711 >
  < mu-law (15), G.711 A-law (16) -> mask bits 0,1,15,16. >
  void create() {
    configure(20, nativeMaskForCodecs());
    verifier = new SLCodecVerifier();
  }

  < The native-id bit mask for codecs: bits 0, 1, 15, 16 set. >
  int nativeMaskForCodecs() {
    int bit15 = 1; int k = 0; while (k < 15) { bit15 = bit15 * 2; k = k + 1; }
    return 1 + 2 + bit15 + (bit15 * 2);
  }

  < ---- resolution (delegated to the wired Verifier) ------------------- >

  < Resolve a codec id from a file extension via the Controller's Verifier. >
  int resolveExtension(String extension) {
    return verifier.resolveExtension(extension);
  }

  < ---- domain verbs (thin wrappers over the inherited dispatch gate) --- >

  < decode(id) / encode(id): a codec's domain operations. Both are gated by the >
  < shared dispatchCode(): -2 invalid, -5 not loaded, -1 backend absent, 0 ok. >
  int decode(int id) { return dispatchCode(id); }
  int encode(int id) { return dispatchCode(id); }

  < ---- identity + result text ----------------------------------------- >
  String serviceName() { return "SLCodecController"; }
  < Human-readable text for a result code (via the wired Verifier, which uses >
  < the shared SLServiceResult vocabulary). >
  String resultText(int code) {
    return verifier.resultText(code);
  }
}