Web Worker中的getUserMedia [英] getUserMedia in a web worker

查看:73
本文介绍了Web Worker中的getUserMedia的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怀疑这个问题的答案是否",但以防万一有人有更多信息...

I suspect the answer to this question is 'no', but just in case anyone has more info...

我正在处理音频和视频,看来简单地将音频样本存储在ScripProcessorNodeonaudioprocess处理程序中(以供以后处理)在低端硬件上占用了多达40%的CPU.这使我的视频处理错过了帧.

I'm processing audio and video and it appears that simply storing audio samples in an ScripProcessorNode's onaudioprocess handler (for later processing) is using up to 40% of CPU on lower end hardware. This is making my video processing miss frames.

我想将音频处理移至Web Worker,但似乎在Web Worker上下文中没有对navigator.webkitGetUserMedia(或任何变体)的访问.

I'd like to move the audio processing to a web worker but there doesn't seem to be any access to navigator.webkitGetUserMedia (or any variants) in a web worker context.

由于我目前仅存储数据,并且造成了如此大的开销,因此我认为将其以消息形式发送给Webworker也会有类似的开销.

As I'm only storing the data at the moment and it's causing such an overhead, I think sending it in a message to the webworker would have a similar overhead.

简而言之,我的问题是:是否可以通过网络工作者直接访问麦克风?

In short, my question is: is there any way to access a microphone directly from a web worker?

推荐答案

不幸的是,答案是否定的. Webworkers不能(直接)访问userMedia.根据您处理数据的方式,您可以从主线程开始,然后使用worker.postMessage将一些工作分担给工作人员.但是,传递给worker.postMessage的任何内容都必须可序列化-例如,它不能是音频流本身.

Unfortunately the answer is no. Webworkers do not have (direct) access to userMedia. Depending on how you're processing the data, you could start in the main thread and use worker.postMessage to offload some work to the worker. However, whatever you pass to worker.postMessage has to be serializable - so it can't be the audio stream itself for example.

这篇关于Web Worker中的getUserMedia的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆