Skip to content

Commit

Permalink
Initial moq-transport-01 support (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
kixelated authored Nov 3, 2023
1 parent 5e7af61 commit b5c545f
Show file tree
Hide file tree
Showing 13 changed files with 423 additions and 144 deletions.
12 changes: 7 additions & 5 deletions lib/contribute/broadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ export class Broadcast {
await subscriber.ack()

const stream = await subscriber.data({
sequence: 0,
priority: 0, // TODO Highest priority
expires: 0, // never expires
group: 0,
object: 0,
priority: 0,
})

const writer = stream.getWriter()
Expand Down Expand Up @@ -164,7 +164,8 @@ export class Broadcast {

// Create a new stream for each segment.
const stream = await subscriber.data({
sequence: 0,
group: 0,
object: 0,
priority: 0, // TODO
expires: 0, // Never expires
})
Expand Down Expand Up @@ -209,7 +210,8 @@ export class Broadcast {
async #serveSegment(subscriber: SubscribeRecv, segment: Segment) {
// Create a new stream for each segment.
const stream = await subscriber.data({
sequence: segment.id,
group: segment.id,
object: 0,
priority: 0, // TODO
expires: 30, // TODO configurable
})
Expand Down
6 changes: 5 additions & 1 deletion lib/media/catalog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export class Catalog {

const { header, stream } = segment

if (header.sequence !== 0) {
if (header.group !== 0) {
throw new Error("TODO updates not supported")
}

if (header.object !== 0) {
throw new Error("TODO delta updates not supported")
}

Expand Down
6 changes: 5 additions & 1 deletion lib/playback/mse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ export default class Player {
track = this.#audio
}

const segment = new Segment(track.source, init, msg.header.sequence)
if (msg.header.object !== 0) {
throw new Error("multiple objects per group not supported")
}

const segment = new Segment(track.source, init, msg.header.group)
track.add(segment)

const container = new MP4.Parser()
Expand Down
6 changes: 5 additions & 1 deletion lib/playback/webcodecs/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ class Worker {

const timeline = msg.kind === "audio" ? this.#timeline.audio : this.#timeline.video

if (msg.header.object !== 0) {
throw new Error("multiple objects per group not supported")
}

// Add the segment to the timeline
const segments = timeline.segments.getWriter()
await segments.write({
sequence: msg.header.sequence,
sequence: msg.header.group,
frames: container.decode.readable,
})
segments.releaseLock()
Expand Down
2 changes: 1 addition & 1 deletion lib/transport/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Client {
const setup = new Setup.Stream(reader, writer)

// Send the setup message.
await setup.send.client({ versions: [Setup.Version.KIXEL_00], role: this.config.role })
await setup.send.client({ versions: [Setup.Version.KIXEL_01], role: this.config.role })

// Receive the setup message.
// TODO verify the SETUP response.
Expand Down
17 changes: 4 additions & 13 deletions lib/transport/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,10 @@ export class Connection {
}

async #recv(msg: Control.Message) {
switch (msg.kind) {
case Control.Msg.Announce:
return this.#subscriber.recvAnnounce(msg)
case Control.Msg.AnnounceOk:
return this.#publisher.recvAnnounceOk(msg)
case Control.Msg.AnnounceReset:
return this.#publisher.recvAnnounceReset(msg)
case Control.Msg.Subscribe:
return this.#publisher.recvSubscribe(msg)
case Control.Msg.SubscribeOk:
return this.#subscriber.recvSubscribeOk(msg)
case Control.Msg.SubscribeReset:
return this.#subscriber.recvSubscribeReset(msg)
if (Control.isPublisher(msg)) {
await this.#subscriber.recv(msg)
} else {
await this.#publisher.recv(msg)
}
}

Expand Down
Loading

0 comments on commit b5c545f

Please sign in to comment.