| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/pepper/pepper_media_stream_audio_track_host.h" | 5 #include "content/renderer/pepper/pepper_media_stream_audio_track_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 using ppapi::host::HostMessageContext; | 27 using ppapi::host::HostMessageContext; |
| 28 using ppapi::MediaStreamAudioTrackShared; | 28 using ppapi::MediaStreamAudioTrackShared; |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // Audio buffer durations in milliseconds. | 32 // Audio buffer durations in milliseconds. |
| 33 const uint32_t kMinDuration = 10; | 33 const uint32_t kMinDuration = 10; |
| 34 const uint32_t kDefaultDuration = 10; | 34 const uint32_t kDefaultDuration = 10; |
| 35 | 35 |
| 36 const int32_t kDefaultNumberOfBuffers = 4; | 36 const int32_t kDefaultNumberOfBuffers = 4; |
| 37 const int32_t kMaxNumberOfBuffers = 1000; // 10 sec | 37 const int32_t kMaxNumberOfAudioBuffers = 1000; // 10 sec |
| 38 | 38 |
| 39 // Returns true if the |sample_rate| is supported in | 39 // Returns true if the |sample_rate| is supported in |
| 40 // |PP_AudioBuffer_SampleRate|, otherwise false. | 40 // |PP_AudioBuffer_SampleRate|, otherwise false. |
| 41 PP_AudioBuffer_SampleRate GetPPSampleRate(int sample_rate) { | 41 PP_AudioBuffer_SampleRate GetPPSampleRate(int sample_rate) { |
| 42 switch (sample_rate) { | 42 switch (sample_rate) { |
| 43 case 8000: | 43 case 8000: |
| 44 return PP_AUDIOBUFFER_SAMPLERATE_8000; | 44 return PP_AUDIOBUFFER_SAMPLERATE_8000; |
| 45 case 16000: | 45 case 16000: |
| 46 return PP_AUDIOBUFFER_SAMPLERATE_16000; | 46 return PP_AUDIOBUFFER_SAMPLERATE_16000; |
| 47 case 22050: | 47 case 22050: |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 context); | 335 context); |
| 336 } | 336 } |
| 337 | 337 |
| 338 int32_t PepperMediaStreamAudioTrackHost::OnHostMsgConfigure( | 338 int32_t PepperMediaStreamAudioTrackHost::OnHostMsgConfigure( |
| 339 HostMessageContext* context, | 339 HostMessageContext* context, |
| 340 const MediaStreamAudioTrackShared::Attributes& attributes) { | 340 const MediaStreamAudioTrackShared::Attributes& attributes) { |
| 341 if (!MediaStreamAudioTrackShared::VerifyAttributes(attributes)) | 341 if (!MediaStreamAudioTrackShared::VerifyAttributes(attributes)) |
| 342 return PP_ERROR_BADARGUMENT; | 342 return PP_ERROR_BADARGUMENT; |
| 343 | 343 |
| 344 int32_t buffers = attributes.buffers | 344 int32_t buffers = attributes.buffers |
| 345 ? std::min(kMaxNumberOfBuffers, attributes.buffers) | 345 ? std::min(kMaxNumberOfAudioBuffers, attributes.buffers) |
| 346 : kDefaultNumberOfBuffers; | 346 : kDefaultNumberOfBuffers; |
| 347 return audio_sink_.Configure(buffers, attributes.duration, | 347 return audio_sink_.Configure(buffers, attributes.duration, |
| 348 context->MakeReplyMessageContext()); | 348 context->MakeReplyMessageContext()); |
| 349 } | 349 } |
| 350 | 350 |
| 351 void PepperMediaStreamAudioTrackHost::OnClose() { | 351 void PepperMediaStreamAudioTrackHost::OnClose() { |
| 352 if (connected_) { | 352 if (connected_) { |
| 353 MediaStreamAudioSink::RemoveFromAudioTrack(&audio_sink_, track_); | 353 MediaStreamAudioSink::RemoveFromAudioTrack(&audio_sink_, track_); |
| 354 connected_ = false; | 354 connected_ = false; |
| 355 } | 355 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 370 // can't happen until the sink is added to the audio track below. | 370 // can't happen until the sink is added to the audio track below. |
| 371 if (format.IsValid()) | 371 if (format.IsValid()) |
| 372 audio_sink_.OnSetFormat(format); | 372 audio_sink_.OnSetFormat(format); |
| 373 | 373 |
| 374 MediaStreamAudioSink::AddToAudioTrack(&audio_sink_, track_); | 374 MediaStreamAudioSink::AddToAudioTrack(&audio_sink_, track_); |
| 375 connected_ = true; | 375 connected_ = true; |
| 376 } | 376 } |
| 377 } | 377 } |
| 378 | 378 |
| 379 } // namespace content | 379 } // namespace content |
| OLD | NEW |