Hi everyone,
I'm working on a custom WebRTC application where one peer is a browser based sender, and the other peer is a C++ native receiver.
Goal
I want to receive both audio and video tracks from the remote peer in my C++ application. The video stream is working correctly. I can attach a VideoSink and process frames as expected. However, audio is not being received even though the browser is sending audio.
For audio I am able to reach onTrack on the C++ application but I cannot reach the OnData.
I'm sending both audio and video from the browser like this:
stream.getAudioTracks().forEach(track => {
this.pc.addTrack(track, stream);
});
stream.getVideoTracks().forEach(track => {
this.pc.addTrack(track, stream);
});
On the JS side, chrome://webrtc-internals shows that audio packets are being sent (framessent number increases, packetssent number increases)
2. C++ application
In my C++ Conductor::OnTrack() handler, I'm successfully receiving the video track, but the audio sink never gets triggered. Here's my code:
void Conductor::OnTrack(rtc::scoped_refptr<webrtc::RtpTransceiverInterface> transceiver)
{
auto track = transceiver->receiver()->track();
printf("\n Inside Conductor::OnTrack"); fflush(stdout);
if (track->kind() == webrtc::MediaStreamTrackInterface::kVideoKind) {
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track =
static_cast<webrtc::VideoTrackInterface*>(track.get());
remote_video_sink_.reset(new VideoFrameExtractor());
rtc::VideoSinkWants wants;
wants.rotation_applied = true;
video_track->AddOrUpdateSink(remote_video_sink_.get(), wants);
std::cout << "OnTrack Video track received and sink attached.\n";
}
else if (track->kind() == webrtc::MediaStreamTrackInterface::kAudioKind) {
rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track =
static_cast<webrtc::AudioTrackInterface*>(track.get());
std::cout << "[OnTrack] Audio track received:\n";
std::cout << " ID : " << audio_track->id() << "\n";
std::cout << " State : " << (audio_track->state() == webrtc::MediaStreamTrackInterface::TrackState::kLive ? "Live" : "Ended") << "\n";
std::cout << " Enabled : " << (audio_track->enabled() ? "true" : "false") << "\n";
remote_audio_sink_.reset(new AudioSinkImpl());
audio_track->AddSink(remote_audio_sink_.get());
printf("\n [OnTrack] Audio track attached.\n"); fflush(stdout);
}
}