Hi all,
I'm trying to play audio from a file to a remote webrtc peer. I can get the peers connected and mic audio flows, no problem. However when I add a stream to the remote peer the audio from the stream doesn't play on the remote peer's system.
This is on Linux using Chrome 56 for the local system and Firefox 51 for the remote peer.
The file loads into the buffer fine, I tested this by attaching a MediaRecorder and monitoring its ondataavailable() event, data is definitely going into buffer.
Here's the basic flow below. What am I doing wrong?
pc1 is the localhost system's AudioContext already set up
mic_patch = pc1.context.createMediaStreamSource( pc1.mic_stream );
// create a new destination from the mic stream
source_dest = pc1.context.createMediaStreamDestination();
// create a new filter
biquadfilter = pc1.context.createBiquadFilter();
biquadfilter.type = 'highpass';
biquadfilter.frequency.value = 1500;
// connect the new mic source to the filter
mic_patch.connect( biquadfilter );
// connect the filter to the new source dest
biquadfilter.connect( source_dest );
After pc2 connects sucessfully to pc1, mic audio works between pc1 and pc2, all is good. Then I add a the source_dest stream to its RTCPeerConnection
pc2.addStream( source_dest.stream );
Then I load a file from disk into a buffer with decodeAudioData(), then put the buffer into the buffer's source, then start playing immediately
# At this point "file" is a File object from a HTML <input type="file"> field
reader = new FileReader();
buffer_source = source_dest.context.createBufferSource();
buffer_source.connect( source_dest );
reader.onload = function(e) {
var arrayBuffer = reader.result;
pc1.context.decodeAudioData( arrayBuffer, function(buffer) {
buffer_source.buffer = buffer;
buffer_source.start(0);
/** For testing to ensure the buffer data makes it into source_dest
mediaRecorder = new MediaRecorder( source_dest.stream );
mediaRecorder.ondataavailable = function(evt) {
// push each chunk (blobs) in an array
chunks.push(evt.data);
// dump out the chunks array to ensure it receives buffer data successfully
console.log( 'CHUNKS', chunks );
};
mediaRecorder.start();
//stop recording after 10 seconds, no need to record longer,
//this is only to test the source_dest connect and data flow
setTimeout( function() { mediaRecorder.stop() }, 10000 )
**/
})
}
reader.readAsArrayBuffer( file.file );
So that's what I have, it all seems to work except for the fact that in my tests the audio data doesn't play on the remote pc2's system.
Any clues as to why?
Thanks in advance for any help that can be offered.