OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/audio_track_recorder.h" | 5 #include "content/renderer/media/audio_track_recorder.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "content/renderer/media/media_stream_audio_track.h" |
13 #include "media/audio/audio_parameters.h" | 14 #include "media/audio/audio_parameters.h" |
14 #include "media/base/audio_bus.h" | 15 #include "media/base/audio_bus.h" |
15 #include "media/base/audio_converter.h" | 16 #include "media/base/audio_converter.h" |
16 #include "media/base/audio_fifo.h" | 17 #include "media/base/audio_fifo.h" |
17 #include "media/base/bind_to_current_loop.h" | 18 #include "media/base/bind_to_current_loop.h" |
18 #include "third_party/opus/src/include/opus.h" | 19 #include "third_party/opus/src/include/opus.h" |
19 | 20 |
20 // Note that this code follows the Chrome media convention of defining a "frame" | 21 // Note that this code follows the Chrome media convention of defining a "frame" |
21 // as "one multi-channel sample" as opposed to another common definition meaning | 22 // as "one multi-channel sample" as opposed to another common definition meaning |
22 // "a chunk of samples". Here this second definition of "frame" is called a | 23 // "a chunk of samples". Here this second definition of "frame" is called a |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 AudioTrackRecorder::AudioTrackRecorder( | 288 AudioTrackRecorder::AudioTrackRecorder( |
288 const blink::WebMediaStreamTrack& track, | 289 const blink::WebMediaStreamTrack& track, |
289 const OnEncodedAudioCB& on_encoded_audio_cb, | 290 const OnEncodedAudioCB& on_encoded_audio_cb, |
290 int32_t bits_per_second) | 291 int32_t bits_per_second) |
291 : track_(track), | 292 : track_(track), |
292 encoder_(new AudioEncoder(media::BindToCurrentLoop(on_encoded_audio_cb), | 293 encoder_(new AudioEncoder(media::BindToCurrentLoop(on_encoded_audio_cb), |
293 bits_per_second)), | 294 bits_per_second)), |
294 encoder_thread_("AudioEncoderThread") { | 295 encoder_thread_("AudioEncoderThread") { |
295 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 296 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
296 DCHECK(!track_.isNull()); | 297 DCHECK(!track_.isNull()); |
297 DCHECK(track_.extraData()); | 298 DCHECK(MediaStreamAudioTrack::From(track_)); |
298 | 299 |
299 // Start the |encoder_thread_|. From this point on, |encoder_| should work | 300 // Start the |encoder_thread_|. From this point on, |encoder_| should work |
300 // only on |encoder_thread_|, as enforced by DCHECKs. | 301 // only on |encoder_thread_|, as enforced by DCHECKs. |
301 DCHECK(!encoder_thread_.IsRunning()); | 302 DCHECK(!encoder_thread_.IsRunning()); |
302 encoder_thread_.Start(); | 303 encoder_thread_.Start(); |
303 | 304 |
304 // Connect the source provider to the track as a sink. | 305 // Connect the source provider to the track as a sink. |
305 MediaStreamAudioSink::AddToAudioTrack(this, track_); | 306 MediaStreamAudioSink::AddToAudioTrack(this, track_); |
306 } | 307 } |
307 | 308 |
(...skipping 21 matching lines...) Expand all Loading... |
329 scoped_ptr<media::AudioBus> audio_data = | 330 scoped_ptr<media::AudioBus> audio_data = |
330 media::AudioBus::Create(audio_bus.channels(), audio_bus.frames()); | 331 media::AudioBus::Create(audio_bus.channels(), audio_bus.frames()); |
331 audio_bus.CopyTo(audio_data.get()); | 332 audio_bus.CopyTo(audio_data.get()); |
332 | 333 |
333 encoder_thread_.task_runner()->PostTask( | 334 encoder_thread_.task_runner()->PostTask( |
334 FROM_HERE, base::Bind(&AudioEncoder::EncodeAudio, encoder_, | 335 FROM_HERE, base::Bind(&AudioEncoder::EncodeAudio, encoder_, |
335 base::Passed(&audio_data), capture_time)); | 336 base::Passed(&audio_data), capture_time)); |
336 } | 337 } |
337 | 338 |
338 } // namespace content | 339 } // namespace content |
OLD | NEW |