Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: media/audio/android/audio_android_unittest.cc

Issue 2041033003: clang-tidy WaitableEvent refactor (Android side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0_windows
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/android/build_info.h" 9 #include "base/android/build_info.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 protected: 432 protected:
433 AudioManager* audio_manager() { return audio_manager_.get(); } 433 AudioManager* audio_manager() { return audio_manager_.get(); }
434 base::MessageLoopForUI* loop() { return loop_.get(); } 434 base::MessageLoopForUI* loop() { return loop_.get(); }
435 const AudioParameters& audio_output_parameters() { 435 const AudioParameters& audio_output_parameters() {
436 return audio_output_parameters_; 436 return audio_output_parameters_;
437 } 437 }
438 438
439 // Synchronously runs the provided callback/closure on the audio thread. 439 // Synchronously runs the provided callback/closure on the audio thread.
440 void RunOnAudioThread(const base::Closure& closure) { 440 void RunOnAudioThread(const base::Closure& closure) {
441 if (!audio_manager()->GetTaskRunner()->BelongsToCurrentThread()) { 441 if (!audio_manager()->GetTaskRunner()->BelongsToCurrentThread()) {
442 base::WaitableEvent event(false, false); 442 base::WaitableEvent event(
443 base::WaitableEvent::ResetPolicy::AUTOMATIC,
444 base::WaitableEvent::InitialState::NOT_SIGNALED);
443 audio_manager()->GetTaskRunner()->PostTask( 445 audio_manager()->GetTaskRunner()->PostTask(
444 FROM_HERE, 446 FROM_HERE,
445 base::Bind(&AudioAndroidOutputTest::RunOnAudioThreadImpl, 447 base::Bind(&AudioAndroidOutputTest::RunOnAudioThreadImpl,
446 base::Unretained(this), 448 base::Unretained(this),
447 closure, 449 closure,
448 &event)); 450 &event));
449 event.Wait(); 451 event.Wait();
450 } else { 452 } else {
451 closure.Run(); 453 closure.Run();
452 } 454 }
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 file_name = kSpeechFile_16b_m_48k; 853 file_name = kSpeechFile_16b_m_48k;
852 } else if (params.sample_rate() == 44100 && params.channels() == 2) { 854 } else if (params.sample_rate() == 44100 && params.channels() == 2) {
853 file_name = kSpeechFile_16b_s_44k; 855 file_name = kSpeechFile_16b_s_44k;
854 } else if (params.sample_rate() == 44100 && params.channels() == 1) { 856 } else if (params.sample_rate() == 44100 && params.channels() == 1) {
855 file_name = kSpeechFile_16b_m_44k; 857 file_name = kSpeechFile_16b_m_44k;
856 } else { 858 } else {
857 FAIL() << "This test supports 44.1kHz and 48kHz mono/stereo only."; 859 FAIL() << "This test supports 44.1kHz and 48kHz mono/stereo only.";
858 return; 860 return;
859 } 861 }
860 862
861 base::WaitableEvent event(false, false); 863 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
864 base::WaitableEvent::InitialState::NOT_SIGNALED);
862 FileAudioSource source(&event, file_name); 865 FileAudioSource source(&event, file_name);
863 866
864 OpenAndStartAudioOutputStreamOnAudioThread(&source); 867 OpenAndStartAudioOutputStreamOnAudioThread(&source);
865 DVLOG(0) << ">> Verify that the file is played out correctly..."; 868 DVLOG(0) << ">> Verify that the file is played out correctly...";
866 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); 869 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout()));
867 StopAndCloseAudioOutputStreamOnAudioThread(); 870 StopAndCloseAudioOutputStreamOnAudioThread();
868 } 871 }
869 872
870 // Start input streaming and run it for ten seconds while recording to a 873 // Start input streaming and run it for ten seconds while recording to a
871 // local audio file. 874 // local audio file.
872 // NOTE: this test requires user interaction and is not designed to run as an 875 // NOTE: this test requires user interaction and is not designed to run as an
873 // automatized test on bots. 876 // automatized test on bots.
874 TEST_P(AudioAndroidInputTest, DISABLED_RunSimplexInputStreamWithFileAsSink) { 877 TEST_P(AudioAndroidInputTest, DISABLED_RunSimplexInputStreamWithFileAsSink) {
875 AudioParameters params = GetInputStreamParameters(); 878 AudioParameters params = GetInputStreamParameters();
876 DVLOG(1) << params; 879 DVLOG(1) << params;
877 MakeAudioInputStreamOnAudioThread(params); 880 MakeAudioInputStreamOnAudioThread(params);
878 881
879 std::string file_name = base::StringPrintf("out_simplex_%d_%d_%d.pcm", 882 std::string file_name = base::StringPrintf("out_simplex_%d_%d_%d.pcm",
880 params.sample_rate(), 883 params.sample_rate(),
881 params.frames_per_buffer(), 884 params.frames_per_buffer(),
882 params.channels()); 885 params.channels());
883 886
884 base::WaitableEvent event(false, false); 887 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
888 base::WaitableEvent::InitialState::NOT_SIGNALED);
885 FileAudioSink sink(&event, params, file_name); 889 FileAudioSink sink(&event, params, file_name);
886 890
887 OpenAndStartAudioInputStreamOnAudioThread(&sink); 891 OpenAndStartAudioInputStreamOnAudioThread(&sink);
888 DVLOG(0) << ">> Speak into the microphone to record audio..."; 892 DVLOG(0) << ">> Speak into the microphone to record audio...";
889 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); 893 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout()));
890 StopAndCloseAudioInputStreamOnAudioThread(); 894 StopAndCloseAudioInputStreamOnAudioThread();
891 } 895 }
892 896
893 // Same test as RunSimplexInputStreamWithFileAsSink but this time output 897 // Same test as RunSimplexInputStreamWithFileAsSink but this time output
894 // streaming is active as well (reads zeros only). 898 // streaming is active as well (reads zeros only).
895 // NOTE: this test requires user interaction and is not designed to run as an 899 // NOTE: this test requires user interaction and is not designed to run as an
896 // automatized test on bots. 900 // automatized test on bots.
897 TEST_P(AudioAndroidInputTest, DISABLED_RunDuplexInputStreamWithFileAsSink) { 901 TEST_P(AudioAndroidInputTest, DISABLED_RunDuplexInputStreamWithFileAsSink) {
898 AudioParameters in_params = GetInputStreamParameters(); 902 AudioParameters in_params = GetInputStreamParameters();
899 DVLOG(1) << in_params; 903 DVLOG(1) << in_params;
900 MakeAudioInputStreamOnAudioThread(in_params); 904 MakeAudioInputStreamOnAudioThread(in_params);
901 905
902 GetDefaultOutputStreamParametersOnAudioThread(); 906 GetDefaultOutputStreamParametersOnAudioThread();
903 DVLOG(1) << audio_output_parameters(); 907 DVLOG(1) << audio_output_parameters();
904 MakeAudioOutputStreamOnAudioThread(audio_output_parameters()); 908 MakeAudioOutputStreamOnAudioThread(audio_output_parameters());
905 909
906 std::string file_name = base::StringPrintf("out_duplex_%d_%d_%d.pcm", 910 std::string file_name = base::StringPrintf("out_duplex_%d_%d_%d.pcm",
907 in_params.sample_rate(), 911 in_params.sample_rate(),
908 in_params.frames_per_buffer(), 912 in_params.frames_per_buffer(),
909 in_params.channels()); 913 in_params.channels());
910 914
911 base::WaitableEvent event(false, false); 915 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
916 base::WaitableEvent::InitialState::NOT_SIGNALED);
912 FileAudioSink sink(&event, in_params, file_name); 917 FileAudioSink sink(&event, in_params, file_name);
913 MockAudioSourceCallback source; 918 MockAudioSourceCallback source;
914 919
915 EXPECT_CALL(source, OnMoreData(NotNull(), _, 0)) 920 EXPECT_CALL(source, OnMoreData(NotNull(), _, 0))
916 .WillRepeatedly(Invoke(RealOnMoreData)); 921 .WillRepeatedly(Invoke(RealOnMoreData));
917 EXPECT_CALL(source, OnError(audio_output_stream_)).Times(0); 922 EXPECT_CALL(source, OnError(audio_output_stream_)).Times(0);
918 923
919 OpenAndStartAudioInputStreamOnAudioThread(&sink); 924 OpenAndStartAudioInputStreamOnAudioThread(&sink);
920 OpenAndStartAudioOutputStreamOnAudioThread(&source); 925 OpenAndStartAudioOutputStreamOnAudioThread(&source);
921 DVLOG(0) << ">> Speak into the microphone to record audio"; 926 DVLOG(0) << ">> Speak into the microphone to record audio";
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); 967 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
963 printf("\n"); 968 printf("\n");
964 StopAndCloseAudioOutputStreamOnAudioThread(); 969 StopAndCloseAudioOutputStreamOnAudioThread();
965 StopAndCloseAudioInputStreamOnAudioThread(); 970 StopAndCloseAudioInputStreamOnAudioThread();
966 } 971 }
967 972
968 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, 973 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest,
969 testing::ValuesIn(RunAudioRecordInputPathTests())); 974 testing::ValuesIn(RunAudioRecordInputPathTests()));
970 975
971 } // namespace media 976 } // namespace media
OLDNEW
« no previous file with comments | « content/renderer/media/android/webmediaplayer_android.cc ('k') | media/gpu/avda_shared_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698