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/bind_to_current_loop.h" | 16 #include "media/base/bind_to_current_loop.h" |
16 #include "third_party/opus/src/include/opus.h" | 17 #include "third_party/opus/src/include/opus.h" |
17 | 18 |
18 // Note that this code follows the Chrome media convention of defining a "frame" | 19 // Note that this code follows the Chrome media convention of defining a "frame" |
19 // as "one multi-channel sample" as opposed to another common definition | 20 // as "one multi-channel sample" as opposed to another common definition |
20 // meaning "a chunk of samples". Here this second definition of "frame" is | 21 // meaning "a chunk of samples". Here this second definition of "frame" is |
21 // called a "buffer"; so what might be called "frame duration" is instead | 22 // called a "buffer"; so what might be called "frame duration" is instead |
22 // "buffer duration", and so on. | 23 // "buffer duration", and so on. |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 AudioTrackRecorder::AudioTrackRecorder( | 269 AudioTrackRecorder::AudioTrackRecorder( |
269 const blink::WebMediaStreamTrack& track, | 270 const blink::WebMediaStreamTrack& track, |
270 const OnEncodedAudioCB& on_encoded_audio_cb, | 271 const OnEncodedAudioCB& on_encoded_audio_cb, |
271 int32_t bits_per_second) | 272 int32_t bits_per_second) |
272 : track_(track), | 273 : track_(track), |
273 encoder_(new AudioEncoder(media::BindToCurrentLoop(on_encoded_audio_cb), | 274 encoder_(new AudioEncoder(media::BindToCurrentLoop(on_encoded_audio_cb), |
274 bits_per_second)), | 275 bits_per_second)), |
275 encoder_thread_("AudioEncoderThread") { | 276 encoder_thread_("AudioEncoderThread") { |
276 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 277 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
277 DCHECK(!track_.isNull()); | 278 DCHECK(!track_.isNull()); |
278 DCHECK(track_.extraData()); | 279 DCHECK(MediaStreamAudioTrack::GetTrack(track_)); |
279 | 280 |
280 // Start the |encoder_thread_|. From this point on, |encoder_| should work | 281 // Start the |encoder_thread_|. From this point on, |encoder_| should work |
281 // only on |encoder_thread_|, as enforced by DCHECKs. | 282 // only on |encoder_thread_|, as enforced by DCHECKs. |
282 DCHECK(!encoder_thread_.IsRunning()); | 283 DCHECK(!encoder_thread_.IsRunning()); |
283 encoder_thread_.Start(); | 284 encoder_thread_.Start(); |
284 | 285 |
285 // Connect the source provider to the track as a sink. | 286 // Connect the source provider to the track as a sink. |
286 MediaStreamAudioSink::AddToAudioTrack(this, track_); | 287 MediaStreamAudioSink::AddToAudioTrack(this, track_); |
287 } | 288 } |
288 | 289 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 if (sample_rate * possible_duration % 1000 == 0) { | 329 if (sample_rate * possible_duration % 1000 == 0) { |
329 return possible_duration; | 330 return possible_duration; |
330 } | 331 } |
331 } | 332 } |
332 | 333 |
333 // Otherwise, couldn't find a good duration. | 334 // Otherwise, couldn't find a good duration. |
334 return 0; | 335 return 0; |
335 } | 336 } |
336 | 337 |
337 } // namespace content | 338 } // namespace content |
OLD | NEW |