Chromium Code Reviews| 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 // Tests PPB_MediaStreamAudioTrack interface. | 5 // Tests PPB_MediaStreamAudioTrack interface. |
| 6 | 6 |
| 7 #include "ppapi/tests/test_media_stream_audio_track.h" | 7 #include "ppapi/tests/test_media_stream_audio_track.h" |
| 8 | 8 |
| 9 #include <stdio.h> | |
|
Peng
2014/05/27 14:35:49
We usual put a blank line between include <> and i
thembrown
2014/05/27 17:11:23
Oups, a leftover from debugging. Removed it.
On 2
| |
| 9 #include "ppapi/c/private/ppb_testing_private.h" | 10 #include "ppapi/c/private/ppb_testing_private.h" |
| 10 #include "ppapi/cpp/audio_buffer.h" | 11 #include "ppapi/cpp/audio_buffer.h" |
| 11 #include "ppapi/cpp/completion_callback.h" | 12 #include "ppapi/cpp/completion_callback.h" |
| 12 #include "ppapi/cpp/instance.h" | 13 #include "ppapi/cpp/instance.h" |
| 13 #include "ppapi/cpp/var.h" | 14 #include "ppapi/cpp/var.h" |
| 14 #include "ppapi/tests/test_utils.h" | 15 #include "ppapi/tests/test_utils.h" |
| 15 #include "ppapi/tests/testing_instance.h" | 16 #include "ppapi/tests/testing_instance.h" |
| 16 | 17 |
| 17 REGISTER_TEST_CASE(MediaStreamAudioTrack); | 18 REGISTER_TEST_CASE(MediaStreamAudioTrack); |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 22 const int32_t kMaxNumberOfBuffers = 1000; | |
| 21 const int32_t kTimes = 3; | 23 const int32_t kTimes = 3; |
| 22 const char kJSCode[] = | 24 const char kJSCode[] = |
| 23 "function gotStream(stream) {" | 25 "function gotStream(stream) {" |
| 24 " test_stream = stream;" | 26 " test_stream = stream;" |
| 25 " var track = stream.getAudioTracks()[0];" | 27 " var track = stream.getAudioTracks()[0];" |
| 26 " var plugin = document.getElementById('plugin');" | 28 " var plugin = document.getElementById('plugin');" |
| 27 " plugin.postMessage(track);" | 29 " plugin.postMessage(track);" |
| 28 "}" | 30 "}" |
| 29 "var constraints = {" | 31 "var constraints = {" |
| 30 " audio: true," | 32 " audio: true," |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 46 case PP_AUDIOBUFFER_SAMPLERATE_44100: | 48 case PP_AUDIOBUFFER_SAMPLERATE_44100: |
| 47 case PP_AUDIOBUFFER_SAMPLERATE_48000: | 49 case PP_AUDIOBUFFER_SAMPLERATE_48000: |
| 48 case PP_AUDIOBUFFER_SAMPLERATE_96000: | 50 case PP_AUDIOBUFFER_SAMPLERATE_96000: |
| 49 case PP_AUDIOBUFFER_SAMPLERATE_192000: | 51 case PP_AUDIOBUFFER_SAMPLERATE_192000: |
| 50 return true; | 52 return true; |
| 51 default: | 53 default: |
| 52 return false; | 54 return false; |
| 53 } | 55 } |
| 54 } | 56 } |
| 55 | 57 |
| 56 } | 58 } // namespace |
| 57 | 59 |
| 58 TestMediaStreamAudioTrack::TestMediaStreamAudioTrack(TestingInstance* instance) | 60 TestMediaStreamAudioTrack::TestMediaStreamAudioTrack(TestingInstance* instance) |
| 59 : TestCase(instance), | 61 : TestCase(instance), |
| 60 event_(instance_->pp_instance()) { | 62 event_(instance_->pp_instance()) { |
| 61 } | 63 } |
| 62 | 64 |
| 63 bool TestMediaStreamAudioTrack::Init() { | 65 bool TestMediaStreamAudioTrack::Init() { |
| 64 return true; | 66 return true; |
| 65 } | 67 } |
| 66 | 68 |
| 67 TestMediaStreamAudioTrack::~TestMediaStreamAudioTrack() { | 69 TestMediaStreamAudioTrack::~TestMediaStreamAudioTrack() { |
| 68 } | 70 } |
| 69 | 71 |
| 70 void TestMediaStreamAudioTrack::RunTests(const std::string& filter) { | 72 void TestMediaStreamAudioTrack::RunTests(const std::string& filter) { |
| 71 RUN_TEST(Create, filter); | 73 RUN_TEST(Create, filter); |
| 72 RUN_TEST(GetBuffer, filter); | 74 RUN_TEST(GetBuffer, filter); |
| 75 RUN_TEST(Configure, filter); | |
| 73 } | 76 } |
| 74 | 77 |
| 75 void TestMediaStreamAudioTrack::HandleMessage(const pp::Var& message) { | 78 void TestMediaStreamAudioTrack::HandleMessage(const pp::Var& message) { |
| 76 if (message.is_resource()) { | 79 if (message.is_resource()) { |
| 77 audio_track_ = pp::MediaStreamAudioTrack(message.AsResource()); | 80 audio_track_ = pp::MediaStreamAudioTrack(message.AsResource()); |
| 78 } | 81 } |
| 79 event_.Signal(); | 82 event_.Signal(); |
| 80 } | 83 } |
| 81 | 84 |
| 82 std::string TestMediaStreamAudioTrack::TestCreate() { | 85 std::string TestMediaStreamAudioTrack::TestCreate() { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 ASSERT_EQ(buffer.GetDataBufferSize(), 0U); | 136 ASSERT_EQ(buffer.GetDataBufferSize(), 0U); |
| 134 ASSERT_TRUE(buffer.GetDataBuffer() == NULL); | 137 ASSERT_TRUE(buffer.GetDataBuffer() == NULL); |
| 135 } | 138 } |
| 136 | 139 |
| 137 // Close the track. | 140 // Close the track. |
| 138 audio_track_.Close(); | 141 audio_track_.Close(); |
| 139 ASSERT_TRUE(audio_track_.HasEnded()); | 142 ASSERT_TRUE(audio_track_.HasEnded()); |
| 140 audio_track_ = pp::MediaStreamAudioTrack(); | 143 audio_track_ = pp::MediaStreamAudioTrack(); |
| 141 PASS(); | 144 PASS(); |
| 142 } | 145 } |
| 146 | |
| 147 std::string TestMediaStreamAudioTrack::TestConfigure() { | |
| 148 // Create a track. | |
| 149 instance_->EvalScript(kJSCode); | |
| 150 event_.Wait(); | |
| 151 event_.Reset(); | |
| 152 | |
| 153 ASSERT_FALSE(audio_track_.is_null()); | |
| 154 ASSERT_FALSE(audio_track_.HasEnded()); | |
| 155 ASSERT_FALSE(audio_track_.GetId().empty()); | |
| 156 | |
| 157 PP_TimeDelta timestamp = 0.0; | |
| 158 | |
| 159 // Configure number of buffers. | |
| 160 struct { | |
| 161 int32_t buffers; | |
| 162 int32_t expect_result; | |
| 163 } buffers[] = { | |
| 164 { 8, PP_OK }, | |
| 165 { 100, PP_OK }, | |
| 166 { kMaxNumberOfBuffers, PP_OK }, | |
| 167 { -1, PP_ERROR_BADARGUMENT }, | |
| 168 { kMaxNumberOfBuffers + 1, PP_OK }, // Clipped to max value. | |
| 169 { 0, PP_OK }, // Use default. | |
| 170 }; | |
| 171 for (size_t i = 0; i < sizeof(buffers) / sizeof(buffers[0]); ++i) { | |
|
Peng
2014/05/27 14:35:49
try using arraysize(buffers)?
thembrown
2014/05/27 17:11:23
arraysize requires including base/macros.h which b
| |
| 172 TestCompletionCallback cc_configure(instance_->pp_instance(), false); | |
| 173 int32_t attrib_list[] = { | |
| 174 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS, buffers[i].buffers, | |
| 175 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE, | |
| 176 }; | |
| 177 cc_configure.WaitForResult( | |
| 178 audio_track_.Configure(attrib_list, cc_configure.GetCallback())); | |
| 179 ASSERT_EQ(buffers[i].expect_result, cc_configure.result()); | |
| 180 | |
| 181 // Get some buffers. This should also succeed when configure fails. | |
| 182 | |
| 183 for (int j = 0; j < kTimes; ++j) { | |
| 184 TestCompletionCallbackWithOutput<pp::AudioBuffer> cc_get_buffer( | |
| 185 instance_->pp_instance(), false); | |
| 186 cc_get_buffer.WaitForResult( | |
| 187 audio_track_.GetBuffer(cc_get_buffer.GetCallback())); | |
| 188 ASSERT_EQ(PP_OK, cc_get_buffer.result()); | |
| 189 pp::AudioBuffer buffer = cc_get_buffer.output(); | |
| 190 ASSERT_FALSE(buffer.is_null()); | |
| 191 ASSERT_TRUE(IsSampleRateValid(buffer.GetSampleRate())); | |
| 192 ASSERT_EQ(buffer.GetSampleSize(), PP_AUDIOBUFFER_SAMPLESIZE_16_BITS); | |
| 193 | |
| 194 ASSERT_GE(buffer.GetTimestamp(), timestamp); | |
| 195 timestamp = buffer.GetTimestamp(); | |
| 196 | |
| 197 ASSERT_GT(buffer.GetDataBufferSize(), 0U); | |
| 198 ASSERT_TRUE(buffer.GetDataBuffer() != NULL); | |
| 199 | |
| 200 audio_track_.RecycleBuffer(buffer); | |
| 201 } | |
| 202 } | |
| 203 | |
| 204 // Configure should fail while plugin holds buffers. | |
| 205 { | |
| 206 TestCompletionCallbackWithOutput<pp::AudioBuffer> cc_get_buffer( | |
| 207 instance_->pp_instance(), false); | |
| 208 cc_get_buffer.WaitForResult( | |
| 209 audio_track_.GetBuffer(cc_get_buffer.GetCallback())); | |
| 210 ASSERT_EQ(PP_OK, cc_get_buffer.result()); | |
| 211 pp::AudioBuffer buffer = cc_get_buffer.output(); | |
| 212 int32_t attrib_list[] = { | |
| 213 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS, 0, | |
| 214 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE, | |
| 215 }; | |
| 216 TestCompletionCallback cc_configure(instance_->pp_instance(), false); | |
| 217 cc_configure.WaitForResult( | |
| 218 audio_track_.Configure(attrib_list, cc_configure.GetCallback())); | |
| 219 ASSERT_EQ(PP_ERROR_INPROGRESS, cc_configure.result()); | |
| 220 audio_track_.RecycleBuffer(buffer); | |
| 221 } | |
| 222 | |
| 223 // Close the track. | |
| 224 audio_track_.Close(); | |
| 225 ASSERT_TRUE(audio_track_.HasEnded()); | |
| 226 audio_track_ = pp::MediaStreamAudioTrack(); | |
| 227 PASS(); | |
| 228 } | |
| OLD | NEW |