Stream audio from Windows application over WebRTC connection

24 views Asked by At

I'm trying to stream audio from a specific Windows process over a WebRTC P2P connection.

I've found a Windows API that allows you to extract the audio from a specific Windows process through a callback: https://github.com/microsoft/Windows-classic-samples/tree/main/Samples/ApplicationLoopback

I'm not an expert on WebRTC, but the P2P connection between 2 clients have been establised.

From what I can tell the next step is to create an audio source that inherits from webrtc::LocalAudioSource and from that create an AudioTrack() and then AddTrack() to the peer connection. But after that I'm not sure how to pipe the audio from the Windows API callback into the audio track?

// Implement AudioSourceInterface
class MyAudioSource : public webrtc::LocalAudioSource {
public:
    MyAudioSource() {}
    ~MyAudioSource() override {}
};

int main() {
    // Initialize PeerConnectionFactory
    rtc::InitializeSSL();
    rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_factory =
            webrtc::CreatePeerConnectionFactory();

    // Create AudioSource
    rtc::scoped_refptr<MyAudioSource> audio_source(new rtc::RefCountedObject<MyAudioSource>());

    // Create AudioTrack
    rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track =
            peer_factory->CreateAudioTrack("audio_track_id", audio_source);

    // Create PeerConnection
    rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection =
            peer_factory->CreatePeerConnection(...);

    // Add audio track to PeerConnection
    peer_connection->AddTrack(audio_track, {});
return 0;
}

I tried the code posted above. The code builds and runs, but I don't know how to pipe audio into the audio track.

0

There are 0 answers