|
| 1 | +# CTE LL-DASH Ingest Implementation Plan |
| 2 | + |
| 3 | +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| 4 | +
|
| 5 | +**Goal:** Add CTE LL-DASH as a live publishing mechanism by accepting multiple concurrent HTTP/1.1 chunked CMAF ingest paths and forwarding resulting live objects through the existing MoQ publisher. |
| 6 | + |
| 7 | +**Architecture:** Implement a small HTTP/1.1 ingest server that accepts `POST`/`PUT` requests with `Transfer-Encoding: chunked`, decodes request bodies incrementally, and feeds decoded bytes into a CMAF live adapter. The adapter reuses `StreamingMp4Reader`, `extract_tracks`, `build_live_catalog`, `build_live_fragment`, and `Publisher::publish_live_objects(...)`, keeping the new surface limited to one live ingest module and CLI wiring. |
| 8 | + |
| 9 | +**Tech Stack:** C++20, POSIX sockets on non-Windows builds, existing MP4/CMAF parser and MoQ publisher API, CMake tests. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## File Structure |
| 14 | + |
| 15 | +- Create `include/openmoq/publisher/live_dash_ingest.h` |
| 16 | + - Public config for the DASH ingest listener. |
| 17 | + - Queue-backed live object source builder. |
| 18 | + - Testable chunked-transfer decoder and CMAF stream adapter. |
| 19 | +- Create `src/live_dash_ingest.cpp` |
| 20 | + - HTTP request parser. |
| 21 | + - Chunked transfer decoder. |
| 22 | + - Multi-path connection handler. |
| 23 | + - CMAF init/media object production. |
| 24 | +- Create `tests/live_dash_ingest_test.cpp` |
| 25 | + - Unit tests for chunked decoding, CMAF object production, and concurrent path behavior. |
| 26 | +- Modify `include/openmoq/publisher/cli_options.h` |
| 27 | + - Add `LiveSourceKind::kDash` and DASH listener options. |
| 28 | +- Modify `src/cli_options.cpp` |
| 29 | + - Parse `--live-source dash`, `--dash-listen`, `--dash-path`, and `--dash-queue-depth`. |
| 30 | +- Modify `src/main.cpp` |
| 31 | + - Start DASH ingest mode and call `Publisher::publish_live_objects(...)`. |
| 32 | +- Modify `CMakeLists.txt` |
| 33 | + - Compile the new module and add the new test executable. |
| 34 | +- Modify `docs/quickstart.md` and `README.md` |
| 35 | + - Document the new ingest mode after implementation. |
| 36 | + |
| 37 | +## Task 1: Plan and Baseline |
| 38 | + |
| 39 | +- [ ] **Step 1: Save this plan** |
| 40 | + |
| 41 | +Create `docs/ctedash-implementation-plan.md` with this content. |
| 42 | + |
| 43 | +- [ ] **Step 2: Verify baseline branch** |
| 44 | + |
| 45 | +Run: |
| 46 | + |
| 47 | +```bash |
| 48 | +git status -sb |
| 49 | +``` |
| 50 | + |
| 51 | +Expected: branch is `feature/ctedash`; only this plan file is new before implementation starts. |
| 52 | + |
| 53 | +## Task 2: Chunked Transfer Decoder |
| 54 | + |
| 55 | +**Files:** |
| 56 | +- Create: `include/openmoq/publisher/live_dash_ingest.h` |
| 57 | +- Create: `src/live_dash_ingest.cpp` |
| 58 | +- Test: `tests/live_dash_ingest_test.cpp` |
| 59 | +- Modify: `CMakeLists.txt` |
| 60 | + |
| 61 | +- [ ] **Step 1: Write failing tests** |
| 62 | + |
| 63 | +Add tests that feed chunked bytes split across arbitrary input boundaries: |
| 64 | + |
| 65 | +```cpp |
| 66 | +ok &= expect_chunked_decodes("4\r\nWiki\r\n5\r\npedia\r\n0\r\n\r\n", "Wikipedia"); |
| 67 | +ok &= expect_chunked_decodes("4;token=value\r\nWiki\r\n0\r\n\r\n", "Wiki"); |
| 68 | +ok &= expect_chunked_rejects("FFFFFFFFFFFFFFFFF\r\nx\r\n0\r\n\r\n"); |
| 69 | +``` |
| 70 | + |
| 71 | +- [ ] **Step 2: Run test to verify it fails** |
| 72 | + |
| 73 | +Run: |
| 74 | + |
| 75 | +```bash |
| 76 | +cmake --build build --target openmoq-publisher-live-dash-tests |
| 77 | +./build/openmoq-publisher-live-dash-tests |
| 78 | +``` |
| 79 | + |
| 80 | +Expected: build or test fails because the new module does not exist yet. |
| 81 | + |
| 82 | +- [ ] **Step 3: Implement minimal decoder** |
| 83 | + |
| 84 | +Implement `ChunkedBodyDecoder::append(...)` and `ChunkedBodyDecoder::take_decoded()` with explicit states for size line, data, data CRLF, trailers, complete, and error. Enforce a configurable max chunk size and reject integer overflow. |
| 85 | + |
| 86 | +- [ ] **Step 4: Run test to verify it passes** |
| 87 | + |
| 88 | +Run the same test command. Expected: all chunked decoder tests pass. |
| 89 | + |
| 90 | +## Task 3: CMAF Live Object Adapter |
| 91 | + |
| 92 | +**Files:** |
| 93 | +- Modify: `include/openmoq/publisher/live_dash_ingest.h` |
| 94 | +- Modify: `src/live_dash_ingest.cpp` |
| 95 | +- Test: `tests/live_dash_ingest_test.cpp` |
| 96 | + |
| 97 | +- [ ] **Step 1: Write failing tests** |
| 98 | + |
| 99 | +Use existing MP4 test helpers to build: |
| 100 | + |
| 101 | +- one init segment containing `ftyp+moov` |
| 102 | +- two `moof+mdat` media pairs on path `/ingest/video` |
| 103 | +- two `moof+mdat` media pairs on path `/ingest/audio` |
| 104 | + |
| 105 | +Assert: |
| 106 | + |
| 107 | +- no media object is emitted before init is available |
| 108 | +- a catalog object is emitted first |
| 109 | +- media objects retain path-specific track names |
| 110 | +- path queues can interleave without blocking each other |
| 111 | + |
| 112 | +- [ ] **Step 2: Run test to verify it fails** |
| 113 | + |
| 114 | +Run: |
| 115 | + |
| 116 | +```bash |
| 117 | +cmake --build build --target openmoq-publisher-live-dash-tests |
| 118 | +./build/openmoq-publisher-live-dash-tests |
| 119 | +``` |
| 120 | + |
| 121 | +Expected: tests fail because the adapter does not exist. |
| 122 | + |
| 123 | +- [ ] **Step 3: Implement adapter** |
| 124 | + |
| 125 | +Implement a queue-backed `LiveDashIngestSession`: |
| 126 | + |
| 127 | +- `ingest(path, bytes)` appends bytes to that path's `StreamingMp4Reader`. |
| 128 | +- `ftyp` and `moov` are buffered as init bytes. |
| 129 | +- tracks are extracted after `moov`. |
| 130 | +- `moof` is held until the following `mdat`. |
| 131 | +- each complete `moof+mdat` becomes a `LiveObject`. |
| 132 | +- group IDs increment independently per track/path. |
| 133 | +- `source()` returns a `LiveObjectSource` with all known tracks plus `catalog`. |
| 134 | + |
| 135 | +- [ ] **Step 4: Run test to verify it passes** |
| 136 | + |
| 137 | +Run the same test command. Expected: adapter tests pass. |
| 138 | + |
| 139 | +## Task 4: HTTP Server and Multiple Concurrent Paths |
| 140 | + |
| 141 | +**Files:** |
| 142 | +- Modify: `src/live_dash_ingest.cpp` |
| 143 | +- Test: `tests/live_dash_ingest_test.cpp` |
| 144 | + |
| 145 | +- [ ] **Step 1: Write failing tests** |
| 146 | + |
| 147 | +Start the ingest server on loopback port `0`, open two client sockets, and send chunked `PUT` requests to `/ingest/video` and `/ingest/audio`. Assert both paths produce objects and that a malformed request gets a `400` response without killing the listener. |
| 148 | + |
| 149 | +- [ ] **Step 2: Run test to verify it fails** |
| 150 | + |
| 151 | +Run: |
| 152 | + |
| 153 | +```bash |
| 154 | +cmake --build build --target openmoq-publisher-live-dash-tests |
| 155 | +./build/openmoq-publisher-live-dash-tests |
| 156 | +``` |
| 157 | + |
| 158 | +Expected: tests fail because server handling is not implemented. |
| 159 | + |
| 160 | +- [ ] **Step 3: Implement server** |
| 161 | + |
| 162 | +Implement `LiveDashIngestServer`: |
| 163 | + |
| 164 | +- bind/listen on configured host/port |
| 165 | +- expose actual bound port for tests |
| 166 | +- accept each connection in its own worker thread |
| 167 | +- parse request line and headers |
| 168 | +- allow only `POST` and `PUT` |
| 169 | +- require path prefix match |
| 170 | +- decode `Transfer-Encoding: chunked` |
| 171 | +- feed decoded bytes into the shared session |
| 172 | +- send `204 No Content` on clean completion and `400`/`405` on invalid input |
| 173 | +- stop cleanly when requested |
| 174 | + |
| 175 | +- [ ] **Step 4: Run test to verify it passes** |
| 176 | + |
| 177 | +Run the same test command. Expected: HTTP server tests pass. |
| 178 | + |
| 179 | +## Task 5: CLI and Publisher Wiring |
| 180 | + |
| 181 | +**Files:** |
| 182 | +- Modify: `include/openmoq/publisher/cli_options.h` |
| 183 | +- Modify: `src/cli_options.cpp` |
| 184 | +- Modify: `src/main.cpp` |
| 185 | +- Test: `tests/cli_options_test.cpp` |
| 186 | + |
| 187 | +- [ ] **Step 1: Write failing CLI tests** |
| 188 | + |
| 189 | +Assert: |
| 190 | + |
| 191 | +```cpp |
| 192 | +--live-source dash --dash-listen 127.0.0.1:8080 --dash-path /ingest --endpoint https://relay.example.com:443/moq |
| 193 | +``` |
| 194 | + |
| 195 | +parses successfully, while missing `--dash-listen` or missing `--endpoint` fails. |
| 196 | + |
| 197 | +- [ ] **Step 2: Run test to verify it fails** |
| 198 | + |
| 199 | +Run: |
| 200 | + |
| 201 | +```bash |
| 202 | +cmake --build build --target openmoq-publisher-cli-tests |
| 203 | +./build/openmoq-publisher-cli-tests |
| 204 | +``` |
| 205 | + |
| 206 | +Expected: tests fail because the CLI mode is not implemented. |
| 207 | + |
| 208 | +- [ ] **Step 3: Implement CLI and main wiring** |
| 209 | + |
| 210 | +Add: |
| 211 | + |
| 212 | +- `LiveSourceKind::kDash` |
| 213 | +- `--dash-listen <host:port>` |
| 214 | +- `--dash-path <prefix>` defaulting to `/ingest` |
| 215 | +- `--dash-queue-depth <count>` defaulting to `128` |
| 216 | + |
| 217 | +In `main.cpp`, start `LiveDashIngestServer`, then publish `server.source()` with `Publisher::publish_live_objects(...)`. |
| 218 | + |
| 219 | +- [ ] **Step 4: Run test to verify it passes** |
| 220 | + |
| 221 | +Run the CLI tests. Expected: all CLI tests pass. |
| 222 | + |
| 223 | +## Task 6: Docs and Final Verification |
| 224 | + |
| 225 | +**Files:** |
| 226 | +- Modify: `README.md` |
| 227 | +- Modify: `docs/quickstart.md` |
| 228 | + |
| 229 | +- [ ] **Step 1: Document usage** |
| 230 | + |
| 231 | +Add a short CTE LL-DASH section with the publisher command and a chunked HTTP producer example. |
| 232 | + |
| 233 | +- [ ] **Step 2: Run complete verification** |
| 234 | + |
| 235 | +Run: |
| 236 | + |
| 237 | +```bash |
| 238 | +cmake --build build |
| 239 | +ctest --test-dir build --output-on-failure |
| 240 | +git diff --check |
| 241 | +``` |
| 242 | + |
| 243 | +Expected: build succeeds, tests pass, and whitespace check passes. |
| 244 | + |
| 245 | +- [ ] **Step 3: Review C++ changes** |
| 246 | + |
| 247 | +Review `git diff HEAD` for correctness, concurrency, ownership, parser overflow handling, and test coverage before commit. |
| 248 | + |
0 commit comments