-
Notifications
You must be signed in to change notification settings - Fork 4k
/
remote-stream-recording.html
210 lines (176 loc) · 8.97 KB
/
remote-stream-recording.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<title>Recording Remote Audio Streams / RecordRTC</title>
<style>
html{
background: rgb(231, 241, 241);
font-family: 'Open Sans', sans-serif;
font-size: 1.2em;
line-height: 1.5;
}
h1 {
text-align: center;
border-bottom: 2px solid rgb(121, 40, 40);
color: rgb(121, 40, 40);
}
blockquote, pre {
border: 1px solid rgb(184, 172, 172);
background: rgb(255, 253, 253);
padding: 5px 11px;
border-radius: 5px;
margin-left: 2em;
}
.highlight {
border: 1px dotted black;
background: yellow;
}
</style>
<blockquote style="background: #f3b7b7;border: 5px solid black;border-radius: 5px;padding: 5px 10px; margin: 10px 20px;">
This demo is <span style="border: 1px dotted red; background: yellow; padding: 2px 5px;">out-dated (published on 2013)</span>. Please check this instead: <a href="https://github.com/muaz-khan/RecordRTC">https://github.com/muaz-khan/RecordRTC</a>
</blockquote>
<h1>Recording Remote Audio Streams / <a href="https://www.webrtc-experiment.com/RecordRTC/">RecordRTC</a></h2>
<blockquote style="text-align:center;padding: 5px 3%;">
Remote audio+video recording is supported in Chrome version >= 49. You have to enable MediaRecorder API via chrome://flags/#enable-experimental-web-platform-features
<br><br>
And test this demo instead: <a href="https://www.webrtc-experiment.com/RTCMultiConnection/RecordRTC-and-RTCMultiConnection.html">RecordRTC-and-RTCMultiConnection.html</a>
</blockquote>
<h2>issue: <a href="http://stackoverflow.com/questions/17475038/recording-a-remote-webrtc-stream-with-recordrtc/17475416#17475416" target="_blank">unable to record remote audio streams using RecordRTC.</a></h2>
<ol>
<li>
<a href="https://code.google.com/p/chromium/issues/detail?id=264611">issue: Support multiple AudioProcessing modules for WebRtc media stream</a> / <a href="https://code.google.com/p/webrtc/issues/detail?id=2192#c15" style="color:red;">Read Latest News</a>
<br /><br />
<blockquote>
Currently we only support one AudioProcessing module for one WebRtc VoiceEngine. This introduces a couple of problems, for example:<br />
# Supporting multiple microphones.<br />
# Different audio tracks might have different constrains.<br />
# When a peer connection has multiple audio tracks, the loggings are not correct in libjingle.<br /><br />
The correct fix to all the problem is that we should be able to have different AudioProcessing module to different audio tracks if they are using different sources or having different constrains.
<br /><br />
<a href="https://code.google.com/p/chromium/issues/detail?id=264611">Ref: #264611</a>
</blockquote>
<br /><br />
<blockquote>
There is also an architectural (legacy) "problem" with the current design/implementation.<br />
The APM related constraints are specified at the getUserMedia layer but are currently applied in PeerConnection which is technically a different API. This means that APIs that support using a MediaStream from gUM (e.g. WebAudio), will currently not get processed audio and that a mediastream will look different (well, rather sound different) to different destination APIs.
<br /><br />
<a href="https://code.google.com/p/chromium/issues/detail?id=264611">Ref: #264611</a>
</blockquote>
<h2>Expected Solution?</h2>
<p>
Upcoming (M37+) "<code>--enable-audio-processor</code>" command-line flag or maybe "<code>--<a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-reviews/2xPcC1ZKUFM">enable-audio-track-processing</a></code>" or maybe:<br />
<pre>
var audioConstraints = {
optional: [],
mandatory: {
googEchoCancellation: true
}
};
navigator.webkitGetUserMedia({ audio: audioConstraints }, onSuccess, onFailure);
</pre>
</p>
</li>
<li>
<a href="https://code.google.com/p/chromium/issues/detail?id=328034">issue: Support feeding remote WebRTC MediaStreamTrack output to WebAudio</a>
</li>
<li>
<a href="https://code.google.com/p/webrtc/issues/detail?id=861">issue: Connect WebRTC MediaStreamTrack output to Web Audio API</a>
</li>
</ol>
<script src="https://cdn.webrtc-experiment.com/RecordRTC.js"></script>
<script>
var offerer, answerer;
window.RTCPeerConnection = window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
window.RTCSessionDescription = window.mozRTCSessionDescription || window.RTCSessionDescription;
window.RTCIceCandidate = window.mozRTCIceCandidate || window.RTCIceCandidate;
navigator.getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia;
window.URL = window.webkitURL || window.URL;
window.iceServers = {
iceServers: [{
url: 'stun:23.21.150.121'
}
]
};
</script>
<script>
var sdpConstraints = {
optional: [{
VoiceActivityDetection: false
}],
mandatory: {
OfferToReceiveAudio: true,
OfferToReceiveVideo: false
}
};
/* offerer */
function offererPeer(stream) {
offerer = new RTCPeerConnection(window.iceServers);
// stream is only attached by offerer
offerer.addStream(stream);
offerer.onicecandidate = function (event) {
if (!event || !event.candidate) return;
answerer.addIceCandidate(event.candidate);
};
offerer.createOffer(function (offer) {
offerer.setLocalDescription(offer);
console.debug('offer sdp', offer.sdp);
answererPeer(offer);
}, function() { }, sdpConstraints);
}
</script>
<script>
/* answerer */
function answererPeer(offer) {
answerer = new RTCPeerConnection(window.iceServers);
// stream that is flowing from offerer toward answerer
answerer.onaddstream = function (event) {
console.debug('remote stream', event.stream);
var recorder = new RecordRTC(event.stream, {
type: 'audio',
recorderType: StereoAudioRecorder // Force StereoAudioRecorder.js for Firefox!
});
recorder.startRecording();
setTimeout(function() {
recorder.stopRecording(function(url) {
if(!!navigator.mozGetUserMedia) {
// skip Firefox! Bcz it supports remote audio/video recordings!
document.querySelector('h2').innerHTML = '<a target="_blank" href="https://www.webrtc-experiment.com/RecordRTC/AudioVideo-on-Firefox.html#comment-2217673960">Firefox supports remote audio recording using StereoAudioRecorder.js!</a>';
}
else {
recorder.getDataURL(function(dataURL) {
if(dataURL.indexOf('AAAAAAAAAAAA') != -1) {
document.querySelector('h2').innerHTML = 'Unable to record remote audio stream.<br />It seems that WebAudio APIs are unable to read/process remote audio stream buffers out of single APM i.e. <a href="https://code.google.com/p/chromium/codesearch#chromium/src/content/renderer/media/media_stream_audio_processor.cc">MediaStreamAudioProcessor</a> / WebRtcAudioCapturer.<br /><textarea style="width:100%;height:100px;">' +dataURL + '</textarea>';
}
console.log('data-url', dataURL);
});
}
console.log('blob', recorder.getBlob());
console.log('virtual url', url);
var audio = document.createElement('audio');
audio.controls = true;
audio.src = url;
document.querySelector('h1').appendChild(document.createElement('br'));
document.querySelector('h1').appendChild(audio);
audio.play();
});
}, 5000);
};
answerer.onicecandidate = function (event) {
if (!event || !event.candidate) return;
offerer.addIceCandidate(event.candidate);
};
answerer.setRemoteDescription(offer);
answerer.createAnswer(function (answer) {
answerer.setLocalDescription(answer);
console.debug('answer sdp', answer.sdp);
offerer.setRemoteDescription(answer);
}, function() { }, sdpConstraints);
}
</script>
<script>
function getUserMedia(callback) {
function onerror(e) {
console.error(e);
}
navigator.getUserMedia({ audio: true }, callback, onerror);
}
getUserMedia(offererPeer);
</script>