-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add safari camera encode support #116
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good!! lets see what we can use for audio https://crates.io/crates/opus-oxide
c09fba3
to
838eeba
Compare
@darioalessandro looks like this package doesn't have any code in it |
Goddam! Clickbait |
838eeba
to
760b964
Compare
…asms Created a wrapper interface for the worklets Implemented worklet usage in peer_decoder and microphone_encoder Cleaned up camera encoder Fixed issues with video rendering in peer decoder
760b964
to
b4ff462
Compare
Starting from https://github.com/mmig/opus-encdec, I had decided to try to use ScriptProcessorNodes to obtain Audio samples -> Encode -> Transmit -> Decode -> Audio samples, but it introduced a ton of delay and artifacts. Also ScriptProcessorNodes are deprecated for good reason. I then tried to use AudioWorklets, but the repo only had a Worklet created for the encoding side so I forked the repo here and created one. Also, I had to rebuild the js / wasm files to make sure all of the source files show up in the same file so it loads easier when adding the JS as a module. I added Google's FreeQueue library (a high performance ring buffer), but I had to change a little bit because it was using SharedArrayBuffer's as its backing and they aren't in the GlobalAudioWorkletScope. Created an AudioWorkletCodec struct that essentially creates and interfaces with the worklet and implemented its usage in the both microphone_encoder and peer_decoder using the respective worklets. As far as testing, I was able to test video on Safari. However, for Audio, after a ton of debugging and trying to figure out what was going on, Safari disables a bunch of Web API features on newer versions if you aren't connecting to a HTTPS endpoint so I wasn't able test Audio fully. Audio from newer Safari browsers to Chrome works, but not very well. I'm not sure how much of that is due to the non-HTTPS endpoint. Video from Chrome to Safari iOS works. Safari iOS has HTTPS issues as well. Safari iOS to Chrome Video has issues. It seems like it is due to this.). Suspended AudioContexts were common in Chrome using AudioBufferSources, but switching to AudioWorklets made it less common. |
What do you think about adding the forked worklet repo as a submodule to this project? |
@alcolmenar you are a rockstar! I'll review your PR today. To use https with safari you could use ngrok to expose your localhost in the internet and get valid https certs: https://ngrok.com/ |
I tried that. Maybe I'm doing something wrong but I figured it wouldn't work since there are a few ports that need to be exposed and a free account only allows 1 at a time. Were you able to get a full test in using it? |
@alcolmenar I am looking at this now |
@darioalessandro how does it look? |
Hey @alcolmenar ! I noticed that there's compiled wasm both encoder/decoder.js workers? do you have the source code for these and license? |
I forked the The compiled wasm is an emscripten compilation of the c implementation of libopus and speexdsp. The license is in the repo already |
A number of things to happen to fully enable Safari support due its lack of support for Web specific APIs used:
VideoFrame
to pipe through theVideoEncoder
MediaStreamTrackProcessor
incamera_encoder.rs
and implement methodopus
codec (Safari doesn't supportAudioEncoder
) most likely going to need a 3rd party library for thisMediaStreamTrackerProcessor
inmicrophone_encoder.rs
and implement methodpeer_decoder.rs
and pipe output through the Web Audio APIs (Safari doesn't supportAudioDecoder
)MediaStreamTrackGenerator
and implement aboveFixes #58