OLD | NEW |
1 // Copyright (c) 2011 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 "ppapi/tests/test_audio.h" | 5 #include "ppapi/tests/test_audio.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "ppapi/c/ppb_audio_config.h" | 9 #include "ppapi/c/ppb_audio_config.h" |
10 #include "ppapi/c/ppb_audio.h" | 10 #include "ppapi/c/ppb_audio.h" |
11 #include "ppapi/cpp/module.h" | 11 #include "ppapi/cpp/module.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 4096 | 57 4096 |
58 }; | 58 }; |
59 | 59 |
60 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSampleRates); i++) { | 60 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSampleRates); i++) { |
61 PP_AudioSampleRate sample_rate = kSampleRates[i]; | 61 PP_AudioSampleRate sample_rate = kSampleRates[i]; |
62 | 62 |
63 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(kRequestFrameCounts); j++) { | 63 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(kRequestFrameCounts); j++) { |
64 // Make a config, create the audio resource, and release the config. | 64 // Make a config, create the audio resource, and release the config. |
65 uint32_t request_frame_count = kRequestFrameCounts[j]; | 65 uint32_t request_frame_count = kRequestFrameCounts[j]; |
66 uint32_t frame_count = audio_config_interface_->RecommendSampleFrameCount( | 66 uint32_t frame_count = audio_config_interface_->RecommendSampleFrameCount( |
67 sample_rate, request_frame_count); | 67 instance_->pp_instance(), sample_rate, request_frame_count); |
68 PP_Resource ac = audio_config_interface_->CreateStereo16Bit( | 68 PP_Resource ac = audio_config_interface_->CreateStereo16Bit( |
69 instance_->pp_instance(), sample_rate, frame_count); | 69 instance_->pp_instance(), sample_rate, frame_count); |
70 ASSERT_TRUE(ac); | 70 ASSERT_TRUE(ac); |
71 PP_Resource audio = audio_interface_->Create( | 71 PP_Resource audio = audio_interface_->Create( |
72 instance_->pp_instance(), ac, TrivialAudioCallback, NULL); | 72 instance_->pp_instance(), ac, TrivialAudioCallback, NULL); |
73 core_interface_->ReleaseResource(ac); | 73 core_interface_->ReleaseResource(ac); |
74 ac = 0; | 74 ac = 0; |
75 | 75 |
76 ASSERT_TRUE(audio); | 76 ASSERT_TRUE(audio); |
77 ASSERT_TRUE(audio_interface_->IsAudio(audio)); | 77 ASSERT_TRUE(audio_interface_->IsAudio(audio)); |
(...skipping 21 matching lines...) Expand all Loading... |
99 } | 99 } |
100 | 100 |
101 // Test that releasing the resource without calling |StopPlayback()| "works". | 101 // Test that releasing the resource without calling |StopPlayback()| "works". |
102 // TODO(viettrungluu): Figure out how to check that |StopPlayback()| properly | 102 // TODO(viettrungluu): Figure out how to check that |StopPlayback()| properly |
103 // waits for in-flight callbacks. | 103 // waits for in-flight callbacks. |
104 std::string TestAudio::TestDestroyNoStop() { | 104 std::string TestAudio::TestDestroyNoStop() { |
105 const PP_AudioSampleRate kSampleRate = PP_AUDIOSAMPLERATE_44100; | 105 const PP_AudioSampleRate kSampleRate = PP_AUDIOSAMPLERATE_44100; |
106 const uint32_t kRequestFrameCount = 2048; | 106 const uint32_t kRequestFrameCount = 2048; |
107 | 107 |
108 uint32_t frame_count = audio_config_interface_->RecommendSampleFrameCount( | 108 uint32_t frame_count = audio_config_interface_->RecommendSampleFrameCount( |
109 kSampleRate, kRequestFrameCount); | 109 instance_->pp_instance(), kSampleRate, kRequestFrameCount); |
110 PP_Resource ac = audio_config_interface_->CreateStereo16Bit( | 110 PP_Resource ac = audio_config_interface_->CreateStereo16Bit( |
111 instance_->pp_instance(), kSampleRate, frame_count); | 111 instance_->pp_instance(), kSampleRate, frame_count); |
112 ASSERT_TRUE(ac); | 112 ASSERT_TRUE(ac); |
113 PP_Resource audio = audio_interface_->Create( | 113 PP_Resource audio = audio_interface_->Create( |
114 instance_->pp_instance(), ac, TrivialAudioCallback, NULL); | 114 instance_->pp_instance(), ac, TrivialAudioCallback, NULL); |
115 core_interface_->ReleaseResource(ac); | 115 core_interface_->ReleaseResource(ac); |
116 ac = 0; | 116 ac = 0; |
117 | 117 |
118 ASSERT_TRUE(audio); | 118 ASSERT_TRUE(audio); |
119 ASSERT_TRUE(audio_interface_->IsAudio(audio)); | 119 ASSERT_TRUE(audio_interface_->IsAudio(audio)); |
120 | 120 |
121 // Start playback and release the resource. | 121 // Start playback and release the resource. |
122 ASSERT_TRUE(audio_interface_->StartPlayback(audio)); | 122 ASSERT_TRUE(audio_interface_->StartPlayback(audio)); |
123 core_interface_->ReleaseResource(audio); | 123 core_interface_->ReleaseResource(audio); |
124 | 124 |
125 PASS(); | 125 PASS(); |
126 } | 126 } |
127 | 127 |
128 std::string TestAudio::TestFailures() { | 128 std::string TestAudio::TestFailures() { |
129 const PP_AudioSampleRate kSampleRate = PP_AUDIOSAMPLERATE_44100; | 129 const PP_AudioSampleRate kSampleRate = PP_AUDIOSAMPLERATE_44100; |
130 const uint32_t kRequestFrameCount = 2048; | 130 const uint32_t kRequestFrameCount = 2048; |
131 | 131 |
132 // Test invalid parameters to |Create()|. | 132 // Test invalid parameters to |Create()|. |
133 | 133 |
134 // We want a valid config for some of our tests of |Create()|. | 134 // We want a valid config for some of our tests of |Create()|. |
135 uint32_t frame_count = audio_config_interface_->RecommendSampleFrameCount( | 135 uint32_t frame_count = audio_config_interface_->RecommendSampleFrameCount( |
136 kSampleRate, kRequestFrameCount); | 136 instance_->pp_instance(), kSampleRate, kRequestFrameCount); |
137 PP_Resource ac = audio_config_interface_->CreateStereo16Bit( | 137 PP_Resource ac = audio_config_interface_->CreateStereo16Bit( |
138 instance_->pp_instance(), kSampleRate, frame_count); | 138 instance_->pp_instance(), kSampleRate, frame_count); |
139 ASSERT_TRUE(ac); | 139 ASSERT_TRUE(ac); |
140 | 140 |
141 // Invalid instance -> failure. | 141 // Invalid instance -> failure. |
142 PP_Resource audio = audio_interface_->Create( | 142 PP_Resource audio = audio_interface_->Create( |
143 0, ac, TrivialAudioCallback, NULL); | 143 0, ac, TrivialAudioCallback, NULL); |
144 ASSERT_EQ(0, audio); | 144 ASSERT_EQ(0, audio); |
145 | 145 |
146 // Invalid config -> failure. | 146 // Invalid config -> failure. |
(...skipping 12 matching lines...) Expand all Loading... |
159 // Test the other functions with an invalid audio resource. | 159 // Test the other functions with an invalid audio resource. |
160 ASSERT_FALSE(audio_interface_->IsAudio(0)); | 160 ASSERT_FALSE(audio_interface_->IsAudio(0)); |
161 ASSERT_EQ(0, audio_interface_->GetCurrentConfig(0)); | 161 ASSERT_EQ(0, audio_interface_->GetCurrentConfig(0)); |
162 ASSERT_FALSE(audio_interface_->StartPlayback(0)); | 162 ASSERT_FALSE(audio_interface_->StartPlayback(0)); |
163 ASSERT_FALSE(audio_interface_->StopPlayback(0)); | 163 ASSERT_FALSE(audio_interface_->StopPlayback(0)); |
164 | 164 |
165 PASS(); | 165 PASS(); |
166 } | 166 } |
167 | 167 |
168 // TODO(viettrungluu): Test that callbacks get called, playback happens, etc. | 168 // TODO(viettrungluu): Test that callbacks get called, playback happens, etc. |
OLD | NEW |