Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/environment.h" | 5 #include "base/environment.h" |
| 6 #include "base/test/test_timeouts.h" | 6 #include "base/test/test_timeouts.h" |
| 7 #include "content/renderer/media/audio_hardware.h" | 7 #include "content/renderer/media/audio_hardware.h" |
| 8 #include "content/renderer/media/webrtc_audio_capturer.h" | 8 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 9 #include "content/renderer/media/webrtc_audio_device_impl.h" | 9 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 10 #include "content/renderer/media/webrtc_audio_renderer.h" | 10 #include "content/renderer/media/webrtc_audio_renderer.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 return media::GetAudioHardwareSampleRate(); | 38 return media::GetAudioHardwareSampleRate(); |
| 39 } | 39 } |
| 40 virtual int GetAudioInputHardwareSampleRate( | 40 virtual int GetAudioInputHardwareSampleRate( |
| 41 const std::string& device_id) OVERRIDE { | 41 const std::string& device_id) OVERRIDE { |
| 42 return media::GetAudioInputHardwareSampleRate(device_id); | 42 return media::GetAudioInputHardwareSampleRate(device_id); |
| 43 } | 43 } |
| 44 virtual media::ChannelLayout GetAudioInputHardwareChannelLayout( | 44 virtual media::ChannelLayout GetAudioInputHardwareChannelLayout( |
| 45 const std::string& device_id) OVERRIDE { | 45 const std::string& device_id) OVERRIDE { |
| 46 return media::GetAudioInputHardwareChannelLayout(device_id); | 46 return media::GetAudioInputHardwareChannelLayout(device_id); |
| 47 } | 47 } |
| 48 virtual int GetAudioOutputBufferSize() OVERRIDE { | |
| 49 return media::GetAudioHardwareBufferSize(); | |
| 50 } | |
| 48 private: | 51 private: |
| 49 DISALLOW_COPY_AND_ASSIGN(AudioUtil); | 52 DISALLOW_COPY_AND_ASSIGN(AudioUtil); |
| 50 }; | 53 }; |
| 51 | 54 |
| 52 class AudioUtilNoHardware : public AudioUtilInterface { | 55 class AudioUtilNoHardware : public AudioUtilInterface { |
| 53 public: | 56 public: |
| 54 AudioUtilNoHardware(int output_rate, int input_rate, | 57 AudioUtilNoHardware(int output_rate, int input_rate, |
| 55 media::ChannelLayout input_channel_layout) | 58 media::ChannelLayout input_channel_layout) |
| 56 : output_rate_(output_rate), | 59 : output_rate_(output_rate), |
| 57 input_rate_(input_rate), | 60 input_rate_(input_rate), |
| 58 input_channel_layout_(input_channel_layout) { | 61 input_channel_layout_(input_channel_layout) { |
| 59 } | 62 } |
| 60 | 63 |
| 61 virtual int GetAudioHardwareSampleRate() OVERRIDE { | 64 virtual int GetAudioHardwareSampleRate() OVERRIDE { |
| 62 return output_rate_; | 65 return output_rate_; |
| 63 } | 66 } |
| 64 virtual int GetAudioInputHardwareSampleRate( | 67 virtual int GetAudioInputHardwareSampleRate( |
| 65 const std::string& device_id) OVERRIDE { | 68 const std::string& device_id) OVERRIDE { |
| 66 return input_rate_; | 69 return input_rate_; |
| 67 } | 70 } |
| 68 virtual media::ChannelLayout GetAudioInputHardwareChannelLayout( | 71 virtual media::ChannelLayout GetAudioInputHardwareChannelLayout( |
| 69 const std::string& device_id) OVERRIDE { | 72 const std::string& device_id) OVERRIDE { |
| 70 return input_channel_layout_; | 73 return input_channel_layout_; |
| 71 } | 74 } |
| 75 virtual int GetAudioOutputBufferSize() OVERRIDE { | |
| 76 return (output_rate_ / 100); | |
| 77 } | |
| 72 | 78 |
| 73 private: | 79 private: |
| 74 int output_rate_; | 80 int output_rate_; |
| 75 int input_rate_; | 81 int input_rate_; |
| 76 media::ChannelLayout input_channel_layout_; | 82 media::ChannelLayout input_channel_layout_; |
| 77 DISALLOW_COPY_AND_ASSIGN(AudioUtilNoHardware); | 83 DISALLOW_COPY_AND_ASSIGN(AudioUtilNoHardware); |
| 78 }; | 84 }; |
| 79 | 85 |
| 80 // Return true if at least one element in the array matches |value|. | 86 // Return true if at least one element in the array matches |value|. |
| 81 bool FindElementInArray(int* array, int size, int value) { | 87 bool FindElementInArray(int* array, int size, int value) { |
| 82 return (std::find(&array[0], &array[0] + size, value) != &array[size]); | 88 return (std::find(&array[0], &array[0] + size, value) != &array[size]); |
| 83 } | 89 } |
| 84 | 90 |
| 85 // This method returns false if a non-supported rate is detected on the | 91 // This method returns false if a non-supported rate is detected on the |
| 86 // input or output side. | 92 // input or output side. |
| 87 // TODO(henrika): add support for automatic fallback to Windows Wave audio | 93 // TODO(henrika): add support for automatic fallback to Windows Wave audio |
| 88 // if a non-supported rate is detected. It is probably better to detect | 94 // if a non-supported rate is detected. It is probably better to detect |
| 89 // invalid audio settings by actually trying to open the audio streams instead | 95 // invalid audio settings by actually trying to open the audio streams instead |
| 90 // of relying on hard coded conditions. | 96 // of relying on hard coded conditions. |
| 91 bool HardwareSampleRatesAreValid() { | 97 bool HardwareSampleRatesAreValid() { |
| 92 // These are the currently supported hardware sample rates in both directions. | 98 // These are the currently supported hardware sample rates in both directions. |
| 93 // The actual WebRTC client can limit these ranges further depending on | 99 // The actual WebRTC client can limit these ranges further depending on |
| 94 // platform but this is the maximum range we support today. | 100 // platform but this is the maximum range we support today. |
| 95 int valid_input_rates[] = {16000, 32000, 44100, 48000, 96000}; | 101 int valid_input_rates[] = {16000, 32000, 44100, 48000, 96000}; |
|
tommi (sloooow) - chröme
2013/01/31 13:42:08
nit: make these const
henrika (OOO until Aug 14)
2013/01/31 14:29:38
Done.
| |
| 96 int valid_output_rates[] = {44100, 48000, 96000}; | 102 int valid_output_rates[] = {16000, 32000, 44100, 48000, 96000}; |
| 97 | 103 |
| 98 // Verify the input sample rate. | 104 // Verify the input sample rate. |
| 99 int input_sample_rate = GetAudioInputSampleRate(); | 105 int input_sample_rate = GetAudioInputSampleRate(); |
| 100 | 106 |
| 101 if (!FindElementInArray(valid_input_rates, arraysize(valid_input_rates), | 107 if (!FindElementInArray(valid_input_rates, arraysize(valid_input_rates), |
| 102 input_sample_rate)) { | 108 input_sample_rate)) { |
| 103 LOG(WARNING) << "Non-supported input sample rate detected."; | 109 LOG(WARNING) << "Non-supported input sample rate detected."; |
| 104 return false; | 110 return false; |
| 105 } | 111 } |
| 106 | 112 |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 EXPECT_EQ(0, file->GetFileDuration(file_path.c_str(), duration, | 476 EXPECT_EQ(0, file->GetFileDuration(file_path.c_str(), duration, |
| 471 webrtc::kFileFormatPcm16kHzFile)); | 477 webrtc::kFileFormatPcm16kHzFile)); |
| 472 EXPECT_NE(0, duration); | 478 EXPECT_NE(0, duration); |
| 473 | 479 |
| 474 EXPECT_EQ(0, file->StartPlayingFileLocally(ch, file_path.c_str(), false, | 480 EXPECT_EQ(0, file->StartPlayingFileLocally(ch, file_path.c_str(), false, |
| 475 webrtc::kFileFormatPcm16kHzFile)); | 481 webrtc::kFileFormatPcm16kHzFile)); |
| 476 | 482 |
| 477 // Play 2 seconds worth of audio and then quit. | 483 // Play 2 seconds worth of audio and then quit. |
| 478 message_loop_.PostDelayedTask(FROM_HERE, | 484 message_loop_.PostDelayedTask(FROM_HERE, |
| 479 MessageLoop::QuitClosure(), | 485 MessageLoop::QuitClosure(), |
| 480 base::TimeDelta::FromSeconds(2)); | 486 base::TimeDelta::FromSeconds(10)); |
| 481 message_loop_.Run(); | 487 message_loop_.Run(); |
| 482 | 488 |
| 483 renderer->Stop(); | 489 renderer->Stop(); |
| 484 EXPECT_EQ(0, base->StopSend(ch)); | 490 EXPECT_EQ(0, base->StopSend(ch)); |
| 485 EXPECT_EQ(0, base->StopPlayout(ch)); | 491 EXPECT_EQ(0, base->StopPlayout(ch)); |
| 486 EXPECT_EQ(0, base->DeleteChannel(ch)); | 492 EXPECT_EQ(0, base->DeleteChannel(ch)); |
| 487 EXPECT_EQ(0, base->Terminate()); | 493 EXPECT_EQ(0, base->Terminate()); |
| 488 } | 494 } |
| 489 | 495 |
| 490 // Uses WebRtcAudioDeviceImpl to play out recorded audio in loopback. | 496 // Uses WebRtcAudioDeviceImpl to play out recorded audio in loopback. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 scoped_ptr<WebRTCTransportImpl> transport( | 554 scoped_ptr<WebRTCTransportImpl> transport( |
| 549 new WebRTCTransportImpl(network.get())); | 555 new WebRTCTransportImpl(network.get())); |
| 550 EXPECT_EQ(0, network->RegisterExternalTransport(ch, *transport.get())); | 556 EXPECT_EQ(0, network->RegisterExternalTransport(ch, *transport.get())); |
| 551 EXPECT_EQ(0, base->StartPlayout(ch)); | 557 EXPECT_EQ(0, base->StartPlayout(ch)); |
| 552 EXPECT_EQ(0, base->StartSend(ch)); | 558 EXPECT_EQ(0, base->StartSend(ch)); |
| 553 renderer->Play(); | 559 renderer->Play(); |
| 554 | 560 |
| 555 LOG(INFO) << ">> You should now be able to hear yourself in loopback..."; | 561 LOG(INFO) << ">> You should now be able to hear yourself in loopback..."; |
| 556 message_loop_.PostDelayedTask(FROM_HERE, | 562 message_loop_.PostDelayedTask(FROM_HERE, |
| 557 MessageLoop::QuitClosure(), | 563 MessageLoop::QuitClosure(), |
| 558 base::TimeDelta::FromSeconds(2)); | 564 base::TimeDelta::FromSeconds(10)); |
| 559 message_loop_.Run(); | 565 message_loop_.Run(); |
| 560 | 566 |
| 561 renderer->Stop(); | 567 renderer->Stop(); |
| 562 EXPECT_EQ(0, base->StopSend(ch)); | 568 EXPECT_EQ(0, base->StopSend(ch)); |
| 563 EXPECT_EQ(0, base->StopPlayout(ch)); | 569 EXPECT_EQ(0, base->StopPlayout(ch)); |
| 564 | 570 |
| 565 EXPECT_EQ(0, base->DeleteChannel(ch)); | 571 EXPECT_EQ(0, base->DeleteChannel(ch)); |
| 566 EXPECT_EQ(0, base->Terminate()); | 572 EXPECT_EQ(0, base->Terminate()); |
| 567 } | 573 } |
| 568 | 574 |
| 569 } // namespace content | 575 } // namespace content |
| OLD | NEW |