-
Notifications
You must be signed in to change notification settings - Fork 126
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
Support Safari 16.5 and iOS Chrome #58
Comments
@darioalessandro hey! thank you for releasing this project. I really think it's a great idea. I did spend some time looking at this issue and it essentially boils down to Safari not currently supporting the MediaStreamTrackGenerator/Processor Web APIs. https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrackGenerator#browser_compatibility They actually just added support for the WebCodecs API which enables VideoEncoder in version 16.4 so it seems slow going. I had found some examples where they used VideoStreamReader/Writer and those have been deprecated already and aren't included in web_sys anymore. It seems like we might be able to use a TransformStream, but my knowledge of Web API's is pretty limited... |
Thanks for looking into this issue!! I think it is worth trying @alcolmenar would you like to take on this task? |
@darioalessandro Sure I can give it a shot. I might need some assistance though at some point if I get stuck. |
@alcolmenar how's it going? |
@darioalessandro hey! I've been a bit busy with other things so I haven't had a chance to start in this yet. I should get working on it later today or tomorrow |
sgtm |
@darioalessandro I've been looking into adding Safari support and I think I've determined a way to do this, but I'm not sure if it is something we want to implement. The main issue here is that Safari doesn't currently support the MediaStreamTrackProcessor/Generator APIs which enables the ability to extract a ReadableStream from a MediaStreamTrack. One way I've seen this done is this:
Here is an example of this done in Javascript. https://github.com/GoogleChromeLabs/webm-wasm/blob/master/demo/live.html We might be able to then use the same Also, I've been struggling a bit on how to implement the JsObject containing the methods necessary for the |
Yes, this will work 😄 you can read the offscreen image straight into a video_frame:
you can modify this method directly: videocall-rs/yew-ui/src/model/encode/camera_encoder.rs Lines 168 to 202 in a629581
You will need to enable the following features in the web-sys crate:
|
@darioalessandro thank you for the response. it definitely helped me out. I was able to get camera_encoding working on Safari and was able to test it locally, but I had to remove the use of the Also, while looking into the Audio side of the equation, it looks like Safari actually doesn't support the |
This is awesome! We use opus for audio encoding so I am sure that we can port it to wasm! This is awesome🏆 |
Adding ChatGPT response regarding audio processing, let me know what you think: if I am receiving the audio chunks via a websocket, how can I then play it using the audio context? ChatGPT Create the AudioContext and ScriptProcessorNode: You'll need to create an AudioContext and a ScriptProcessorNode (or AudioWorklet if available) to handle the incoming chunks. Set Up the WebSocket: You'll need to set up the WebSocket connection to receive the audio chunks. Make sure you know the audio format and sample rate. Decode and Play Audio Chunks: As chunks are received, you'll need to decode them (if necessary) and then add them to a buffer that the ScriptProcessorNode can play. Here's some sample code that outlines this process:
Note that this example assumes the audio is being sent in a compatible format (e.g., Float32Array) and doesn't require additional decoding. If the audio is being sent in a compressed format, you'll need to decode it before adding it to the queue. Additionally, precise synchronization and buffer handling might require careful tuning and consideration of the specific requirements of your application. This is a basic and illustrative example. For a production environment, more refined and error-tolerant code would be necessary. Make sure to handle different WebSocket events properly and control the audio buffer efficiently to avoid glitches or interruptions in the playback. |
Ah that makes sense. From my understanding, iOS chrome uses the same engine as Safari |
Damn! So chrome just uses the iOS WebView, that is bad :( |
@darioalessandro it appears that using a processor or a worklet in the Audio graph is the way to go here outside of using WebRTC. In the worklet, we'll need to use a 3rd party opus encoder / decoder. I was thinking about using this: https://github.com/mmig/opus-encdec There don't seem to appear to be any Rust implementations of opus. Also, this'll probably take me a bit of time to figure out. I'm pretty far out of my wheel house here |
This helps a lot! Do you think we should fallback to webrtc for old browsers? We could terminate the webrtc connections on the backend and transform the streams to the other protobuf protocol |
I think there'd be better support for it since many of the video conferencing platforms use it. However, I do think that if we use WebRTC for part of the app, it'd make sense to use it for all of media transfers. But that'd be a large change and possibly not in the spirit of this app. There is an idea of an SFU (Selective Forwarding Unit) in the WebRTC world which is similar to what this app is doing but instead using web sockets and protobufs. It can work using the solution above though and imo probably easier? |
Go with using a processor or a worklet in the Audio graph is the way to go here outside of using WebRTC. In the worklet, we'll need to use a 3rd party opus encoder / decoder. I was thinking about using this: https://github.com/mmig/opus-encdec |
@alcolmenar are you pursuing this? |
hey ya still working on it. I should have something for the encode side soon |
According to MDN and caniuse.com, |
Seems like Safari is missing some classes that our App relies on, we need to find a way around it or at least show an error:
The text was updated successfully, but these errors were encountered: