diff --git a/doc/Client-Portal Protocol.md b/doc/Client-Portal Protocol.md
index 02e7a4857..30b8f0eab 100644
--- a/doc/Client-Portal Protocol.md
+++ b/doc/Client-Portal Protocol.md
@@ -362,36 +362,41 @@ This a format for client reconnects.
```
object(PublicationRequest)::
{
- media: object(WebRTCMediaOptions) | null,
+ media: object(MediaOptions) | null,
data: true | false,
transport: object(TransportOptions),
attributes: object(ClientDefinedAttributes) | null
}
```
-A publication can send either media or data, but a QUIC *transport* channel can support multiple stream for both media and data. Setting `media:null` and `data:false` is meaningless, so it should be rejected by server. Protocol itself doesn't forbit to create WebRTC connection for data. However, SCTP data channel is not implemented at server side, so currently `data:true` is only support by QUIC transport channels.
+A publication can send either media or data. Setting `media:null` and `data:false` is meaningless, so it should be rejected by server. Protocol itself doesn't forbid to create WebRTC connection for data. However, SCTP data channel is not implemented at server side, so currently `data:true` is only support by WebTransport channels.
```
- object(WebRTCMediaOptions)::
+ object(MediaOptions)::
{
tracks: [
{
type: "audio" | "video",
- mid: string(MID),
+ mid: string(MID) | undefined, /* undefined if transport's type is "quic" */
source: "mic" | "screen-cast" | ... | "encoded-file",
+ format: object(AudioFormat) | object(VideoFormat) | undefined /* undefined if transport's type is "webrtc" */
}
]
}
}
```
+
**ResponseData**: The PublicationResult object with following definition if **ResponseStatus** is “ok”:
+```
object(PublicationResult)::
{
transportId: string(transportId), // Can be reused in the following publication or subscription.
id: string(SessionId) //will be used as the stream id when it gets ready.
}
+```
+
### 3.3.8 Participant Stops Publishing a Stream to Room
**RequestName**: “unpublish”
diff --git a/doc/design/pics/.gitkeep b/doc/design/pics/.gitkeep
deleted file mode 100644
index e69de29bb..000000000
diff --git a/doc/design/pics/quic_agent_data_flow.svg b/doc/design/pics/quic_agent_data_flow.svg
new file mode 100644
index 000000000..fc9bc7639
--- /dev/null
+++ b/doc/design/pics/quic_agent_data_flow.svg
@@ -0,0 +1,397 @@
+
+
+
+
diff --git a/doc/design/quic-agent.md b/doc/design/quic-agent.md
new file mode 100644
index 000000000..b50c154ea
--- /dev/null
+++ b/doc/design/quic-agent.md
@@ -0,0 +1,115 @@
+# QUIC agent
+
+## Overview
+QUIC agents are designed for [WebTransport](https://w3c.github.io/webtransport/) over HTTP/3 connections. A WebTransport connection could send and receive arbitrary data, as well as media data encoded or can be decoded by [WebCodecs](https://www.w3.org/TR/webcodecs/).
+
+## Architecture and dataflow
+
+![data flow](./pics/quic_agent_data_flow.svg)
+
+A WebTransportFrameSource handles all audio and video frames for a publication. A WebTransportFrameDestination dispatches audio and video frames to different WebTransport streams or a datagram sender.
+
+A DatagramSource processes datagrams (RTP packets) received from client side, depacketizes them to create audio or video frames, and dispatches media frames to a WebTransportFrameSource. It also handles FEC and NACK, similar to RTCRtpReceiver in WebRTC. A DatagramDestination is similar to RTCRtpSender.
+
+## WebTransport payload and message format
+
+This section defines the payload and message format for data transmitted over WebTransport.
+
+### Streams
+
+Both server and client can initialize a stream. When a stream is created, initial side sends a session ID, which is a 128 bit length message to the remote side. Session ID could be a publication ID or subscription ID as defined in [Client-Portal Protocol](https://github.com/open-webrtc-toolkit/owt-server/blob/master/doc/Client-Portal%20Protocol.md). As the session ID issued by server may less than 128 bit right now, fill it with 0 in most significant bits. Session ID 0 is reserved for signaling. When remote side receives the session ID, it should check whether session ID is valid. Terminate the stream if session ID is invalid, or send the same session ID to client if it is valid. Depends on the type of stream it created, one side or both sides are ready to send data.
+
+### Datagram
+
+Each package has a 128 bit header for session ID.
+
+```
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | |
+ | Session Identifier |
+ | .... |
+ | |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Datagram Data (*) ...
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+```
+
+It may increase about 2% network cost.
+
+### Signaling Session
+
+After creating a WebTransport, a stream with session 0 should be created for authentication and signaling. Every signaling message is followed by a 32 bit length integer that indicates the body's length.
+
+```
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Message length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Message ...
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+```
+
+### Media Stream
+
+After sending 128 bit length session ID, a 128 bit length track ID is sent to remote side to indicates the track of a stream. Since audio track and video track of a single stream shares the same track ID at this time, track 1 is for audio and track 2 is for video.
+
+When a WebTransport stream is used for transmitting data of a media stream track (e.g.: H.264 bitstream), a 32 (8+24) bit length header is added to indicate frame size.
+
+```
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Reserved | Message length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Message ...
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+```
+
+### Authentication
+
+If signaling messages are transmitted over WebTransport, authentication follows the regular process defined by [Client-Portal Protocol](https://github.com/open-webrtc-toolkit/owt-server/blob/master/doc/Client-Portal%20Protocol.md). Otherwise, client sends a token for WebTransport as a signaling message. WebTransport token is issued during joining a conference. If the token is valid, server sends a 128 bit length zeros to client.
+
+## Build conference server with QUIC agent
+
+Because we don't have a good place to store pre-built QUIC SDK for public access, QUIC agent is not enabled by default. Additional flags are required to enable QUIC agent.
+
+1. Download QUIC SDK from the URL specified [here](https://github.com/open-webrtc-toolkit/owt-server/blob/master/source/agent/addons/quic/quic_sdk_url). QUIC SDK is hosted on GitHub as an artifact. You will need to follow [this description](https://docs.github.com/en/rest/reference/actions#download-an-artifact) to make a REST request to GitHub. Or you can download the latest QUIC SDK from [GitHub Actions](https://github.com/open-webrtc-toolkit/owt-sdk-quic/actions) tab. Commits pushed to main branch have artifact for downloading.
+1. After running `installDeps.sh`, put headers to build/libdeps/build/include, and put libraries(.so file) to build/libdeps/build/lib.
+1. Append `-t quic` to the arguments for build.js.
+1. Append `-t quic-agent` to the arguments for pack.js.
+
+## Certificate for QUIC
+
+OWT Conference Server is using a self-signed certificate during development phase, which would be only valid for 14 days. You can use a CA-signed certificate to avoid refreshing the certificate periodically. A CA-signed certificate is recommended for production environment. WebTransport connection will fail if certificate is not valid or expires.
+
+### Certificates signed by a trusted CA
+
+- Copy your PKCS12 format certificate to `quic_agent/cert/` directory to replace the one there.
+- Restart Conference Server QUIC agent to apply the change.
+- Don't provide any fingerprint in client applications.
+
+### Generate self-signed certificates
+
+#### Precondition
+- Make sure you are running the tool under Linux and,
+- Openssl tool is correctly setup in your system.
+- Download the tool under chromium/src/net/tools/quic/certs/ from chromium project ([v93.0.4575.1](https://chromium.googlesource.com/chromium/src/+archive/refs/tags/93.0.4575.1/net/tools/quic/certs.tar.gz.)) to local directory named `tool`. This contains three files: `ca.cnf`, `generate-certs.sh` and `leaf.cnf`.
+
+#### Certificate Generation
+
+- Modify leaf.cnf, adding an entry into `other_hosts` section.
+- Make sure generate-certs.sh is executable. If not, run `chmod +x generate-certs.sh`;
+- Remove the `out` dir in case it exists.
+- Under the downloaded tool dir, run `./generate-certs.sh`. It is expected to generate a series of files under out dir.
+- Under the downloaded tool dir, run `openssl pkcs12 -inkey out/leaf_cert.key -in out/leaf_cert.pem -export -out out/certificate.pfx`. This will prompt for password for the pfx. Please type the certificate password of your conference server. The default password is `abc123`.
+- Under the downloaded tool dir, run `openssl x509 -noout -fingerprint -sha256 -inform pem -in out/leaf_cert.pem`. You will get the fingerprint string in the form of "XX:XX:XX....XX:XX".
+
+#### Use the Certificate
+
+- Copy the generated certificate.pfx under `out` dir to `quic_agent/cert/` dir to replace the one there.
+- Restart Conference Server QUIC agent to apply the change.
+- If you're using JavaScript sample for QUIC, make sure you also update JS sample with the new fingerprint.
+- In your native client sample, make sure you include the fingerprint of new cert in the `ConferenceClientConfiguration.trusted_quic_certificate_fingerprints` you passed to `ConferenceClient` ctor. See more details in the conference sample.
diff --git a/doc/design/quic-programming-guide.md b/doc/design/quic-programming-guide.md
index 129e061b3..f6134e845 100644
--- a/doc/design/quic-programming-guide.md
+++ b/doc/design/quic-programming-guide.md
@@ -123,15 +123,6 @@ Please see the conference sample application for more detailed usage.
Please follow [Conference Server build instructions](https://github.com/open-webrtc-toolkit/owt-server/blob/master/README.md) on how to build and deploy the conference server.
-## Build Conference Server with QUIC agent
-
-Because we don't have a good place to store pre-built QUIC SDK for public access, QUIC agent is not enabled by default. Additional flags are required to enable QUIC agent.
-
-1. Download QUIC SDK from the URL specified [here](https://github.com/open-webrtc-toolkit/owt-server/blob/master/source/agent/addons/quic/quic_sdk_url). QUIC SDK is hosted on GitHub as an artifact. You will need to follow [this description](https://docs.github.com/en/rest/reference/actions#download-an-artifact) to make a REST request to GitHub. Or you can download the latest QUIC SDK from [GitHub Actions](https://github.com/open-webrtc-toolkit/owt-sdk-quic/actions) tab. Commits pushed to main branch have artifact for downloading.
-1. After running `installDeps.sh`, put headers to build/libdeps/build/include, and put libraries(.so file) to build/libdeps/build/lib.
-1. Append `-t quic` to the arguments for build.js.
-1. Append `-t quic-agent` to the arguments for pack.js.
-
## How to use Pre-built Conference Server Binary
Steps to run Conference Server with pre-built binary:
@@ -146,30 +137,4 @@ Steps to run Conference Server with pre-built binary:
# OWT QUIC Windows Sample
-The Windows sample will be provided in OWT repo separately. More details will be provided later.
-
-# How to Replace the Certificate for QUIC
-
-OWT Conference Server is using a self-signed certificate during development phase, which would be only valid for 14 days. You can use a CA-signed certificate to avoid refreshing the certificate periodically. WebTransport connection will fail if certificate is not valid or expires.
-
-## Precondition
-
-- Make sure you are running the tool under Linux and,
-- Openssl tool is correctly setup in your system.
-- Download the tool under chromium/src/net/tools/quic/certs/ from chromium project to local dir named `tool`. This contains three files: `ca.cnf`, `generate-certs.sh` and `leaf.cnf`.
-
-## Certificate Generation
-
-- Modify leaf.cnf, adding an entry into `other_hosts` section.
-- Make sure generate-certs.sh is exectuable. If not, run `chmod +x generate-certs.sh`;
-- Remove the `out` dir in case it exists.
-- Under the downloaded tool dir, run `./generate-certs.sh`. It is expected to generate a series of files under out dir.
-- Under the downloaded tool dir, run `openssl pkcs12 -inkey out/leaf_cert.key -in out/leaf_cert.pem -export -out out/certificate.pfx`. This will prompt for password for the pfx. Make sure you always use `abc123` as the password.
-- Under the downloaded tool dir, run `openssl x509 -noout -fingerprint -sha256 -inform pem -in out/leaf_cert.pem`. You will get the fingerprint string in the form of "XX:XX:XX....XX:XX".
-
-## Use the Certificate
-
-- Copy the generated certificate.pfx under `out` dir to `quic_agent/cert/` dir to replace the one there.
-- Restart Conference Server QUIC agent to apply the change. If you're using JS sample for QUIC, make sure you also update JS sample with the new fingerprint.
-- In your native client sample, make sure you include the fingerprint of new cert in the `ConferenceClientConfiguration.trusted_quic_certificate_fingerprints` you passed to `ConferenceClient` ctor. See more details in the conference sample.
-
+The Windows sample will be provided in OWT repo separately. More details will be provided later.
\ No newline at end of file
diff --git a/doc/design/quic-transport-payload-format.md b/doc/design/quic-transport-payload-format.md
deleted file mode 100644
index 6102c5887..000000000
--- a/doc/design/quic-transport-payload-format.md
+++ /dev/null
@@ -1,44 +0,0 @@
-# QUIC Transport Payload and Message Format
-
-This post defines the payload and message format for data transmitted over [WebTransport](https://w3c.github.io/webtransport/#web-transport).
-
-## Streams
-
-Both server and client can initialize a stream. When a stream is created, initial side sends a session ID, which is a 128 bit length message to the remote side. Session ID could be a publication ID or subscription ID as defined in [Client-Portal Protocol](https://github.com/open-webrtc-toolkit/owt-server/blob/master/doc/Client-Portal%20Protocol.md). As the session ID issued by server may less than 128 bit right now, fill it with 0 in most significant bits. Session ID 0 is reserved for signaling. When remote side receives the session ID, it should check whether session ID is valid. Terminate the stream if session ID is invalid, or send the same session ID to client if it is valid. Depends on the type of stream it created, one side or both sides are ready to send data.
-
-## Datagram
-
-Each package has a 128 bit header for session ID.
-
-```
- 0 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | Session Identifier |
- | .... |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Datagram Data (*) ...
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-```
-
-It may increase about 2% network cost.
-
-## Signaling Session
-
-After creating a WebTransport, a stream with session 0 should be created for authentication and signaling. Every signaling message is followed by a 32 bit length integer that indicates the body's length.
-
-```
- 0 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Message length |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Message ...
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-```
-
-## Authentication
-
-If signaling messages are transmitted over WebTransport, authentication follows the regular process defined by [Client-Portal Protocol](https://github.com/open-webrtc-toolkit/owt-server/blob/master/doc/Client-Portal%20Protocol.md). Otherwise, client sends a token for WebTransport as a signaling message. WebTransport token is issued during joining a conference. If the token is valid, server sends a 128 bit length zeros to client.
\ No newline at end of file
diff --git a/source/agent/addons/common/MediaFramePipelineWrapper.h b/source/agent/addons/common/MediaFramePipelineWrapper.h
index 8b3f5ba3f..112714357 100644
--- a/source/agent/addons/common/MediaFramePipelineWrapper.h
+++ b/source/agent/addons/common/MediaFramePipelineWrapper.h
@@ -6,10 +6,10 @@
#ifndef MEDIAFRAMEPIPELINEWRAPPER_H
#define MEDIAFRAMEPIPELINEWRAPPER_H
+#include
+#include
#include
#include
-#include
-
/*
* Wrapper class of owt_base::FrameDestination
@@ -30,5 +30,13 @@ class FrameSource : public node::ObjectWrap{
owt_base::FrameSource* src;
};
+/*
+ * Nan::ObjectWrap of owt_base::FrameSource and owt_base::FrameDestination, represents a node in the media or data pipeline.
+ */
+class NanFrameNode : public Nan::ObjectWrap {
+public:
+ virtual owt_base::FrameSource* FrameSource() = 0;
+ virtual owt_base::FrameDestination* FrameDestination() = 0;
+};
#endif
\ No newline at end of file
diff --git a/source/agent/addons/internalIO/InternalClientWrapper.cc b/source/agent/addons/internalIO/InternalClientWrapper.cc
index 357844bcc..d0d4d257c 100644
--- a/source/agent/addons/internalIO/InternalClientWrapper.cc
+++ b/source/agent/addons/internalIO/InternalClientWrapper.cc
@@ -88,23 +88,36 @@ NAN_METHOD(InternalClient::close) {
obj->me = nullptr;
}
-NAN_METHOD(InternalClient::addDestination) {
- InternalClient* obj = ObjectWrap::Unwrap(info.Holder());
- owt_base::InternalClient* me = obj->me;
+NAN_METHOD(InternalClient::addDestination)
+{
+ InternalClient* obj = ObjectWrap::Unwrap(info.Holder());
+ owt_base::InternalClient* me = obj->me;
- Nan::Utf8String param0(Nan::To(info[0]).ToLocalChecked());
- std::string track = std::string(*param0);
+ Nan::Utf8String param0(Nan::To(info[0]).ToLocalChecked());
+ std::string track = std::string(*param0);
- FrameDestination* param =
- ObjectWrap::Unwrap(
- info[1]->ToObject(Nan::GetCurrentContext()).ToLocalChecked());
- owt_base::FrameDestination* dest = param->dest;
+ bool isNanDestination(false);
+ if (info.Length() >= 3) {
+ isNanDestination = info[2]->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->Value();
+ }
- if (track == "audio") {
- me->addAudioDestination(dest);
- } else if (track == "video") {
- me->addVideoDestination(dest);
- }
+ owt_base::FrameDestination* dest(nullptr);
+ if (isNanDestination) {
+ NanFrameNode* param = Nan::ObjectWrap::Unwrap(info[1]->ToObject());
+ dest = param->FrameDestination();
+ } else {
+ FrameDestination* param = ObjectWrap::Unwrap(
+ info[1]->ToObject(Nan::GetCurrentContext()).ToLocalChecked());
+ dest = param->dest;
+ }
+
+ if (track == "audio") {
+ me->addAudioDestination(dest);
+ } else if (track == "video") {
+ me->addVideoDestination(dest);
+ } else if (track == "data") {
+ me->addDataDestination(dest);
+ }
}
NAN_METHOD(InternalClient::removeDestination) {
diff --git a/source/agent/addons/internalIO/InternalServerWrapper.cc b/source/agent/addons/internalIO/InternalServerWrapper.cc
index 0443a2838..efe1d0cb0 100644
--- a/source/agent/addons/internalIO/InternalServerWrapper.cc
+++ b/source/agent/addons/internalIO/InternalServerWrapper.cc
@@ -99,10 +99,20 @@ NAN_METHOD(InternalServer::addSource) {
Nan::Utf8String param0(Nan::To(info[0]).ToLocalChecked());
std::string streamId = std::string(*param0);
- FrameSource* param =
- ObjectWrap::Unwrap(
- info[1]->ToObject(Nan::GetCurrentContext()).ToLocalChecked());
- owt_base::FrameSource* src = param->src;
+ bool isNanSource(false);
+ if (info.Length() >= 3) {
+ isNanSource = info[2]->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->Value();
+ }
+
+ owt_base::FrameSource* src(nullptr);
+ if (isNanSource) {
+ NanFrameNode* param = Nan::ObjectWrap::Unwrap(info[1]->ToObject());
+ src = param->FrameSource();
+ } else {
+ FrameSource* param = ObjectWrap::Unwrap(
+ info[1]->ToObject(Nan::GetCurrentContext()).ToLocalChecked());
+ src = param->src;
+ }
me->addSource(streamId, src);
}
diff --git a/source/agent/addons/internalIO/InternalServerWrapper.h b/source/agent/addons/internalIO/InternalServerWrapper.h
index 65831e980..8ffce22ab 100644
--- a/source/agent/addons/internalIO/InternalServerWrapper.h
+++ b/source/agent/addons/internalIO/InternalServerWrapper.h
@@ -44,7 +44,10 @@ class InternalServer : public node::ObjectWrap,
static NAN_METHOD(close);
static NAN_METHOD(getListeningPort);
-
+ // Arguments:
+ // type: string, type of the source, "audio", "video" or "data".
+ // source: A node addon object or NAN object.
+ // isNanObject: indicates whether `source` is a NAN object.
static NAN_METHOD(addSource);
static NAN_METHOD(removeSource);
diff --git a/source/agent/addons/quic/QuicTransportStream.cc b/source/agent/addons/quic/QuicTransportStream.cc
index 5a86d8de4..88fc88bf7 100644
--- a/source/agent/addons/quic/QuicTransportStream.cc
+++ b/source/agent/addons/quic/QuicTransportStream.cc
@@ -5,6 +5,7 @@
*/
#include "QuicTransportStream.h"
+#include "../common/MediaFramePipelineWrapper.h"
using v8::Function;
using v8::FunctionTemplate;
@@ -18,6 +19,7 @@ DEFINE_LOGGER(QuicTransportStream, "QuicTransportStream");
Nan::Persistent QuicTransportStream::s_constructor;
const int uuidSizeInBytes = 16;
+const int frameHeaderSize = 4;
QuicTransportStream::QuicTransportStream()
: QuicTransportStream(nullptr)
@@ -25,11 +27,21 @@ QuicTransportStream::QuicTransportStream()
}
QuicTransportStream::QuicTransportStream(owt::quic::WebTransportStreamInterface* stream)
: m_stream(stream)
- , m_contentSessionId()
- , m_receivedContentSessionId(false)
+ , m_contentSessionId(uuidSizeInBytes)
+ , m_receivedContentSessionIdSize(0)
+ , m_trackId(uuidSizeInBytes)
+ , m_receivedTrackIdSize(0)
+ , m_readingTrackId(false)
, m_isPiped(false)
+ , m_hasSink(false)
, m_buffer(nullptr)
, m_bufferSize(0)
+ , m_isMedia(false)
+ , m_readingFrameSize(false)
+ , m_frameSizeOffset(0)
+ , m_frameSizeArray(new uint8_t[frameHeaderSize])
+ , m_currentFrameSize(0)
+ , m_receivedFrameOffset(0)
{
}
@@ -38,6 +50,9 @@ QuicTransportStream::~QuicTransportStream()
if (!uv_is_closing(reinterpret_cast(&m_asyncOnContentSessionId))) {
uv_close(reinterpret_cast(&m_asyncOnContentSessionId), NULL);
}
+ if (!uv_is_closing(reinterpret_cast(&m_asyncOnTrackId))) {
+ uv_close(reinterpret_cast(&m_asyncOnTrackId), NULL);
+ }
if (!uv_is_closing(reinterpret_cast(&m_asyncOnData))) {
uv_close(reinterpret_cast(&m_asyncOnData), NULL);
}
@@ -47,8 +62,10 @@ QuicTransportStream::~QuicTransportStream()
void QuicTransportStream::OnCanRead()
{
- if (!m_receivedContentSessionId) {
- MaybeReadContentSessionId();
+ if (m_receivedContentSessionIdSize < uuidSizeInBytes) {
+ ReadContentSessionId();
+ } else if (m_readingTrackId) {
+ ReadTrackId();
} else {
SignalOnData();
}
@@ -64,6 +81,37 @@ void QuicTransportStream::OnFinRead()
ELOG_DEBUG("On FIN read.");
}
+void QuicTransportStream::AddedDestination()
+{
+ m_hasSink = true;
+ if (m_stream->ReadableBytes() > 0) {
+ SignalOnData();
+ }
+}
+
+void QuicTransportStream::RemovedDestination()
+{
+ // When all destinations are removed, set m_hasSink to false.
+}
+
+void QuicTransportStream::addAudioDestination(owt_base::FrameDestination* dest)
+{
+ owt_base::FrameSource::addAudioDestination(dest);
+ AddedDestination();
+}
+
+void QuicTransportStream::addVideoDestination(owt_base::FrameDestination* dest)
+{
+ owt_base::FrameSource::addVideoDestination(dest);
+ AddedDestination();
+};
+
+void QuicTransportStream::addDataDestination(owt_base::FrameDestination* dest)
+{
+ owt_base::FrameSource::addDataDestination(dest);
+ AddedDestination();
+};
+
NAN_MODULE_INIT(QuicTransportStream::init)
{
Local tpl = Nan::New(newInstance);
@@ -72,7 +120,9 @@ NAN_MODULE_INIT(QuicTransportStream::init)
instanceTpl->SetInternalFieldCount(1);
Nan::SetPrototypeMethod(tpl, "write", write);
+ Nan::SetPrototypeMethod(tpl, "readTrackId", readTrackId);
Nan::SetPrototypeMethod(tpl, "addDestination", addDestination);
+ Nan::SetAccessor(instanceTpl, Nan::New("isMedia").ToLocalChecked(), isMediaGetter, isMediaSetter);
s_constructor.Reset(Nan::GetFunction(tpl).ToLocalChecked());
Nan::Set(target, Nan::New("QuicTransportStream").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked());
@@ -87,6 +137,7 @@ NAN_METHOD(QuicTransportStream::newInstance)
QuicTransportStream* obj = new QuicTransportStream();
obj->Wrap(info.This());
uv_async_init(uv_default_loop(), &obj->m_asyncOnContentSessionId, &QuicTransportStream::onContentSessionId);
+ uv_async_init(uv_default_loop(), &obj->m_asyncOnTrackId, &QuicTransportStream::onTrackId);
uv_async_init(uv_default_loop(), &obj->m_asyncOnData, &QuicTransportStream::onData);
info.GetReturnValue().Set(info.This());
}
@@ -113,20 +164,54 @@ NAN_METHOD(QuicTransportStream::close)
NAN_METHOD(QuicTransportStream::addDestination)
{
QuicTransportStream* obj = Nan::ObjectWrap::Unwrap(info.Holder());
- if (info.Length() != 2) {
+ if (info.Length() > 3) {
Nan::ThrowTypeError("Invalid argument length for addDestination.");
return;
}
- // TODO: Check if info[0] is an Nan wrapped object.
- auto framePtr = Nan::ObjectWrap::Unwrap(info[1]->ToObject());
- // void* ptr = info[0]->ToObject()->GetAlignedPointerFromInternalField(0);
- // auto framePtr=static_cast(ptr);
- obj->addDataDestination(framePtr);
- obj->m_isPiped = true;
+ Nan::Utf8String param0(Nan::To(info[0]).ToLocalChecked());
+ std::string track = std::string(*param0);
+ bool isNanDestination(false);
+ if (info.Length() == 3) {
+ isNanDestination = info[2]->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->Value();
+ }
+ owt_base::FrameDestination* dest(nullptr);
+ if (isNanDestination) {
+ NanFrameNode* param = Nan::ObjectWrap::Unwrap(info[1]->ToObject());
+ dest = param->FrameDestination();
+ } else {
+ ::FrameDestination* param = node::ObjectWrap::Unwrap<::FrameDestination>(
+ info[1]->ToObject(Nan::GetCurrentContext()).ToLocalChecked());
+ dest = param->dest;
+ }
+ if (track == "audio") {
+ obj->addAudioDestination(dest);
+ } else if (track == "video") {
+ obj->addVideoDestination(dest);
+ } else if (track == "data") {
+ obj->addDataDestination(dest);
+ }
}
NAN_METHOD(QuicTransportStream::removeDestination)
{
+ QuicTransportStream* obj = Nan::ObjectWrap::Unwrap(info.Holder());
+ obj->m_hasSink = false;
+}
+
+NAN_METHOD(QuicTransportStream::readTrackId){
+ QuicTransportStream* obj = Nan::ObjectWrap::Unwrap(info.Holder());
+ obj->ReadTrackId();
+}
+
+NAN_GETTER(QuicTransportStream::isMediaGetter){
+ QuicTransportStream* obj = Nan::ObjectWrap::Unwrap(info.Holder());
+ info.GetReturnValue().Set(Nan::New(obj->m_isMedia));
+}
+
+NAN_SETTER(QuicTransportStream::isMediaSetter)
+{
+ QuicTransportStream* obj = Nan::ObjectWrap::Unwrap(info.Holder());
+ obj->m_isMedia = value->ToBoolean(Nan::GetCurrentContext()).ToLocalChecked()->Value();
}
v8::Local QuicTransportStream::newInstance(owt::quic::WebTransportStreamInterface* stream)
@@ -134,29 +219,51 @@ v8::Local QuicTransportStream::newInstance(owt::quic::WebTransportSt
Local