简体   繁体   English

播放时更改音频渲染器端点

[英]Changing audio renderer endpoint while playing

I'm writing an audio player using Microsoft Media Foundation.我正在使用 Microsoft Media Foundation 编写音频播放器。 I wonder is it possible to change the playback device without re-creating the session?我想知道是否可以在不重新创建会话的情况下更改播放设备?

IMFActivate *m_p_sink_activate;
...
m_p_sink_activate->SetString(MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ID, name_device);

This doesn't take effect if the audio is already being played.如果音频已经在播放,这不会生效。

Btw, the media player provided by Microsoft.Windows.SDK.Contracts (Windows.Media.Playback.MediaPlayer) does it perfectly.顺便说一句,Microsoft.Windows.SDK.Contracts (Windows.Media.Playback.MediaPlayer) 提供的媒体播放器做得很完美。 When I change m_mediaPlayer.AudioDevice, the audio stream is redirected to the assigned device immediately.当我更改 m_mediaPlayer.AudioDevice 时,音频流会立即重定向到指定的设备。 So I wonder if this is also possible for MSMF.所以我想知道这是否也适用于 MSMF。

So far I have a way could do this job,到目前为止,我有办法完成这项工作,

  1. Create a new topology which cloned from previous one.创建一个从前一个克隆的新拓扑。
  2. Create new audio renderer using MFCreateAudioRendererActivate and using set string with the new audio endpoint ID add it to a topologynode;使用 MFCreateAudioRendererActivate 创建新的音频渲染器,并使用带有新音频端点 ID 的设置字符串将其添加到拓扑节点;
  3. Add the new node to new topology;将新节点添加到新拓扑中;
  4. Using IMFMediaSession::SetTopology() do set new topology to play.使用 IMFMediaSession::SetTopology() 设置要播放的新拓扑。

You could refer to MS sample TopoEdit for detail.您可以参考 MS 示例 TopoEdit 了解详细信息。

One side effect is that each time SetTopology cause huge memory growth.一个副作用是每次 SetTopology 都会导致巨大的内存增长。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM