aiortc / aioquic

QUIC and HTTP/3 implementation in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Test] Indefinite/infinite stream from server to client

guest271314 opened this issue · comments

There does not appear to be any means to sustain an indefinite/infinite stream (for example, streaming a live jam session; full-length movie or live event; web radio station) using either datagrams or streams using aioquic.

Kindly create tests for indefinite/infinite streams using datagrams and streams (where only one (1) write to server is used to start the stream) from server to client.

I missed your PR?

No. You closed the handshake issue which last time I tested on Chromium, did not work using this repository.

I am requesting that you write code testing the use case indefinite/infinite stream from client to server, since you know how your code works, I do not, yet.

OK, feel free to re-open with a PR, I don't understand what you want.

Write a test that streams data infinitely from server to client using a WebTransport stream.

I tried to stream live audio. The data does not stream continuously. It appears some internal buffer keeps growing (when observing task manager) and the stream does not reach the client.

TL;DR

I can capture system audio output and send to browser using this code as host for Native Messaging

#!/usr/bin/env -S python3 -u
# https://github.com/mdn/webextensions-examples/pull/157

import sys
import json
import struct
import argparse
import os
import subprocess
from shlex import split

try:
    # Python 3.x version
    # Read a message from stdin and decode it.
    def getMessage():
        rawLength = sys.stdin.buffer.read(4)
        if len(rawLength) == 0:
            sys.exit(0)
        messageLength = struct.unpack('@I', rawLength)[0]
        message = sys.stdin.buffer.read(messageLength).decode('utf-8')
        return json.loads(message)

    # Encode a message for transmission,
    # given its content.
    def encodeMessage(messageContent):
        encodedContent = json.dumps(messageContent).encode('utf-8')
        encodedLength = struct.pack('@I', len(encodedContent))
        return {'length': encodedLength, 'content': encodedContent}

    # Send an encoded message to stdout
    def sendMessage(encodedMessage):
        sys.stdout.buffer.write(encodedMessage['length'])
        sys.stdout.buffer.write(encodedMessage['content'])
        sys.stdout.buffer.flush()

    while True:
        receivedMessage = getMessage()
        process = subprocess.Popen(split(receivedMessage), stdout=subprocess.PIPE)
        os.set_blocking(process.stdout.fileno(), False)
        for chunk in iter(lambda: process.stdout.read(1024 * 1024), b''):
            if chunk is not None:
                encoded = str([int('%02X' % i, 16) for i in chunk])
                sendMessage(encodeMessage(encoded))                       
except Exception as e:
    sys.stdout.buffer.flush()
    sys.stdin.buffer.flush()
    sys.exit(0)

which uses around 12MB.

When I try to do the same with WebTransport RAM usage starts over 20MB keep growing and the stream does not reach the browser continously.

I am essentially trying to verify if WebTransport and aioquic are suitable for live-streaming media. And not just one track. An indeterminate stream, for example, a live jam session, which can be hours of audio, etc.

So far I have not been able to do that using your repository. That is why I ask you, the expert, to test the use case described. Either aioquic and WebTransport do or don;t support live streaming an infinite stream.

Another way to put this issue is how would you live-stream audio with WebTransport?