| 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" | |
| 14 #include "media/audio/audio_parameters.h" | 13 #include "media/audio/audio_parameters.h" |
| 15 #include "media/base/audio_bus.h" | 14 #include "media/base/audio_bus.h" |
| 16 #include "media/base/audio_converter.h" | 15 #include "media/base/audio_converter.h" |
| 17 #include "media/base/audio_fifo.h" | 16 #include "media/base/audio_fifo.h" |
| 18 #include "media/base/bind_to_current_loop.h" | 17 #include "media/base/bind_to_current_loop.h" |
| 19 #include "third_party/opus/src/include/opus.h" | 18 #include "third_party/opus/src/include/opus.h" |
| 20 | 19 |
| 21 // Note that this code follows the Chrome media convention of defining a "frame" | 20 // Note that this code follows the Chrome media convention of defining a "frame" |
| 22 // as "one multi-channel sample" as opposed to another common definition meaning | 21 // as "one multi-channel sample" as opposed to another common definition meaning |
| 23 // "a chunk of samples". Here this second definition of "frame" is called a | 22 // "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... |
| 288 AudioTrackRecorder::AudioTrackRecorder( | 287 AudioTrackRecorder::AudioTrackRecorder( |
| 289 const blink::WebMediaStreamTrack& track, | 288 const blink::WebMediaStreamTrack& track, |
| 290 const OnEncodedAudioCB& on_encoded_audio_cb, | 289 const OnEncodedAudioCB& on_encoded_audio_cb, |
| 291 int32_t bits_per_second) | 290 int32_t bits_per_second) |
| 292 : track_(track), | 291 : track_(track), |
| 293 encoder_(new AudioEncoder(media::BindToCurrentLoop(on_encoded_audio_cb), | 292 encoder_(new AudioEncoder(media::BindToCurrentLoop(on_encoded_audio_cb), |
| 294 bits_per_second)), | 293 bits_per_second)), |
| 295 encoder_thread_("AudioEncoderThread") { | 294 encoder_thread_("AudioEncoderThread") { |
| 296 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 295 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 297 DCHECK(!track_.isNull()); | 296 DCHECK(!track_.isNull()); |
| 298 DCHECK(MediaStreamAudioTrack::From(track_)); | 297 DCHECK(track_.extraData()); |
| 299 | 298 |
| 300 // Start the |encoder_thread_|. From this point on, |encoder_| should work | 299 // Start the |encoder_thread_|. From this point on, |encoder_| should work |
| 301 // only on |encoder_thread_|, as enforced by DCHECKs. | 300 // only on |encoder_thread_|, as enforced by DCHECKs. |
| 302 DCHECK(!encoder_thread_.IsRunning()); | 301 DCHECK(!encoder_thread_.IsRunning()); |
| 303 encoder_thread_.Start(); | 302 encoder_thread_.Start(); |
| 304 | 303 |
| 305 // Connect the source provider to the track as a sink. | 304 // Connect the source provider to the track as a sink. |
| 306 MediaStreamAudioSink::AddToAudioTrack(this, track_); | 305 MediaStreamAudioSink::AddToAudioTrack(this, track_); |
| 307 } | 306 } |
| 308 | 307 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 330 scoped_ptr<media::AudioBus> audio_data = | 329 scoped_ptr<media::AudioBus> audio_data = |
| 331 media::AudioBus::Create(audio_bus.channels(), audio_bus.frames()); | 330 media::AudioBus::Create(audio_bus.channels(), audio_bus.frames()); |
| 332 audio_bus.CopyTo(audio_data.get()); | 331 audio_bus.CopyTo(audio_data.get()); |
| 333 | 332 |
| 334 encoder_thread_.task_runner()->PostTask( | 333 encoder_thread_.task_runner()->PostTask( |
| 335 FROM_HERE, base::Bind(&AudioEncoder::EncodeAudio, encoder_, | 334 FROM_HERE, base::Bind(&AudioEncoder::EncodeAudio, encoder_, |
| 336 base::Passed(&audio_data), capture_time)); | 335 base::Passed(&audio_data), capture_time)); |
| 337 } | 336 } |
| 338 | 337 |
| 339 } // namespace content | 338 } // namespace content |
| OLD | NEW |