小编Tim*_*Tim的帖子

MutationObserver 和 Shadow DOM

我正在使用 Polymer 的 ShadowDOM 和 polyfillsMutationObserver并且需要:

  • 检测何时HTMLCanvasElement插入 a 以便我可以执行布局(当从 DOM 树分离时,它的宽度和高度未通过offsetWidth/确定offsetHeight
  • 检测元素何时被移除,以便我可以停止其requestAnimationFrame循环

传统上,如果没有 Shadow DOM,其工作方式如下:

  1. 附加MutationObserver到任何画布元素document.body并对其执行querySelectorAll
  2. 执行一些方法,例如layoutNode在这些元素上
  3. 如果在动画循环中document.body.contains(node)返回false,则该节点已从 DOM 中移除

使用 Shadow DOM 时,我可以通过执行(似乎非常低效)扫描 DOM 中具有已添加根的所有元素,并layoutNode在继承自HTMLCanvasElement.

如何从画布的动画循环中检查该节点是否仍在 DOM 树中?

是否有更好的 API 用于检测何时插入了 DOM 节点?

(注意。使用 Polymer 的 CustomElements polyfill 时 MutationEvents 不可用。)

html javascript dom mutation-observers shadow-dom

6
推荐指数
1
解决办法
2037
查看次数

Safari为什么放弃对SharedWorker的支持?

Safari为什么放弃对SharedWorker的支持?

是否有任何有效的polyfill使用例如localStorage和StorageEvent作为通信端口?(是的,填充程序必须检测并重新创建主Worker)

javascript safari html5 web-worker

5
推荐指数
1
解决办法
2873
查看次数

从原始PCM流使用CMSampleTimingInfo,CMSampleBuffer和AudioBufferList

我从Google的WebRTC C++参考实现(插入一个钩子VoEBaseImpl::GetPlayoutData)接收原始PCM流.音频似乎是线性PCM,签名为int16,但是当使用AssetWriter录制时,它会将音频文件保存为高度失真和高音调.

我假设这是一个输入参数的错误,很可能是关于将stereo-int16转换为AudioBufferList然后转换为CMSampleBuffer.以下代码有什么问题吗?

void RecorderImpl::RenderAudioFrame(void* audio_data, size_t number_of_frames, int sample_rate, int64_t elapsed_time_ms, int64_t ntp_time_ms) {
    OSStatus status;

    AudioChannelLayout acl;
    bzero(&acl, sizeof(acl));
    acl.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;

    AudioStreamBasicDescription audioFormat;
    audioFormat.mSampleRate = sample_rate;
    audioFormat.mFormatID = kAudioFormatLinearPCM;
    audioFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
    audioFormat.mFramesPerPacket = 1;
    audioFormat.mChannelsPerFrame = 2;
    audioFormat.mBitsPerChannel = 16;
    audioFormat.mBytesPerPacket = audioFormat.mFramesPerPacket * audioFormat.mChannelsPerFrame * audioFormat.mBitsPerChannel / 8;
    audioFormat.mBytesPerFrame = audioFormat.mBytesPerPacket / audioFormat.mFramesPerPacket;

    CMSampleTimingInfo timing = { CMTimeMake(1, sample_rate), CMTimeMake(elapsed_time_ms, 1000), kCMTimeInvalid };

    CMFormatDescriptionRef format = NULL;
    status = CMAudioFormatDescriptionCreate(kCFAllocatorDefault, &audioFormat, …
Run Code Online (Sandbox Code Playgroud)

objective-c core-audio ios webrtc

5
推荐指数
2
解决办法
1534
查看次数