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

Side by Side Diff: ppapi/tests/test_audio.cc

Issue 10868034: Fix back-to-back StartPlayback/StopPlayback issue in PPAPI IPC proxy (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/tests/test_audio.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "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"
(...skipping 28 matching lines...) Expand all
39 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); 39 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE));
40 return audio_interface_ && audio_config_interface_ && core_interface_; 40 return audio_interface_ && audio_config_interface_ && core_interface_;
41 } 41 }
42 42
43 void TestAudio::RunTests(const std::string& filter) { 43 void TestAudio::RunTests(const std::string& filter) {
44 RUN_TEST(Creation, filter); 44 RUN_TEST(Creation, filter);
45 RUN_TEST(DestroyNoStop, filter); 45 RUN_TEST(DestroyNoStop, filter);
46 RUN_TEST(Failures, filter); 46 RUN_TEST(Failures, filter);
47 RUN_TEST(AudioCallback1, filter); 47 RUN_TEST(AudioCallback1, filter);
48 RUN_TEST(AudioCallback2, filter); 48 RUN_TEST(AudioCallback2, filter);
49 RUN_TEST(AudioCallback3, filter);
49 } 50 }
50 51
51 // Test creating audio resources for all guaranteed sample rates and various 52 // Test creating audio resources for all guaranteed sample rates and various
52 // frame counts. 53 // frame counts.
53 std::string TestAudio::TestCreation() { 54 std::string TestAudio::TestCreation() {
54 static const PP_AudioSampleRate kSampleRates[] = { 55 static const PP_AudioSampleRate kSampleRates[] = {
55 PP_AUDIOSAMPLERATE_44100, 56 PP_AUDIOSAMPLERATE_44100,
56 PP_AUDIOSAMPLERATE_48000 57 PP_AUDIOSAMPLERATE_48000
57 }; 58 };
58 static const uint32_t kRequestFrameCounts[] = { 59 static const uint32_t kRequestFrameCounts[] = {
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 ASSERT_TRUE(callback_fired_); 280 ASSERT_TRUE(callback_fired_);
280 test_done_ = true; 281 test_done_ = true;
281 282
282 // If any more audio callbacks are generated, we should crash (which is good). 283 // If any more audio callbacks are generated, we should crash (which is good).
283 audio_callback_method_ = NULL; 284 audio_callback_method_ = NULL;
284 test_callback_ = PP_CompletionCallback(); 285 test_callback_ = PP_CompletionCallback();
285 286
286 PASS(); 287 PASS();
287 } 288 }
288 289
290 // This is the same as |TestAudioCallback1()|, except that it attempts a second
291 // round of |StartPlayback| and |StopPlayback| to make sure the callback
292 // function still responds when using the same audio resource.
293 std::string TestAudio::TestAudioCallback3() {
294 const PP_AudioSampleRate kSampleRate = PP_AUDIOSAMPLERATE_44100;
295 const uint32_t kRequestFrameCount = 1024;
296
297 uint32_t frame_count = audio_config_interface_->RecommendSampleFrameCount(
298 instance_->pp_instance(), kSampleRate, kRequestFrameCount);
299 PP_Resource ac = audio_config_interface_->CreateStereo16Bit(
300 instance_->pp_instance(), kSampleRate, frame_count);
301 ASSERT_TRUE(ac);
302 audio_callback_method_ = NULL;
303 PP_Resource audio = audio_interface_->Create(
304 instance_->pp_instance(), ac, AudioCallbackTrampoline, this);
305 core_interface_->ReleaseResource(ac);
306 ac = 0;
307
308 // |AudioCallbackTest()| calls |test_callback_|, sleeps a bit, then sets
309 // |test_done_|.
310 TestCompletionCallback test_callback_1(instance_->pp_instance());
311 test_callback_ = static_cast<pp::CompletionCallback>(
312 test_callback_1).pp_completion_callback();
313 test_done_ = false;
314 callback_fired_ = false;
315
316 audio_callback_method_ = &TestAudio::AudioCallbackTest;
317 ASSERT_TRUE(audio_interface_->StartPlayback(audio));
318
319 // Wait for the audio callback to be called.
320 test_callback_1.WaitForResult();
321 ASSERT_EQ(kMagicValue, test_callback_1.result());
322
323 ASSERT_TRUE(audio_interface_->StopPlayback(audio));
324
325 // |StopPlayback()| should wait for the audio callback to finish.
326 ASSERT_TRUE(callback_fired_);
327
328 TestCompletionCallback test_callback_2(instance_->pp_instance());
329 test_callback_ = static_cast<pp::CompletionCallback>(
330 test_callback_2).pp_completion_callback();
331
332 // Repeat one more |StartPlayback| & |StopPlayback| cycle, and verify again
333 // that the callback function was invoked.
334 callback_fired_ = false;
335 ASSERT_TRUE(audio_interface_->StartPlayback(audio));
336
337 // Wait for the audio callback to be called.
338 test_callback_2.WaitForResult();
339 ASSERT_EQ(kMagicValue, test_callback_2.result());
340
341 ASSERT_TRUE(audio_interface_->StopPlayback(audio));
342
343 // |StopPlayback()| should wait for the audio callback to finish.
344 ASSERT_TRUE(callback_fired_);
345
346 test_done_ = true;
347
348 // If any more audio callbacks are generated, we should crash (which is good).
349 audio_callback_method_ = NULL;
350 test_callback_ = PP_CompletionCallback();
351
352 core_interface_->ReleaseResource(audio);
353
354 PASS();
355 }
356
357
289 // TODO(raymes): Test that actually playback happens correctly, etc. 358 // TODO(raymes): Test that actually playback happens correctly, etc.
290 359
291 static void Crash() { 360 static void Crash() {
292 *static_cast<volatile unsigned*>(NULL) = 0xdeadbeef; 361 *static_cast<volatile unsigned*>(NULL) = 0xdeadbeef;
293 } 362 }
294 363
295 // static 364 // static
296 void TestAudio::AudioCallbackTrampoline(void* sample_buffer, 365 void TestAudio::AudioCallbackTrampoline(void* sample_buffer,
297 uint32_t buffer_size_in_bytes, 366 uint32_t buffer_size_in_bytes,
298 void* user_data) { 367 void* user_data) {
(...skipping 16 matching lines...) Expand all
315 uint32_t buffer_size_in_bytes) { 384 uint32_t buffer_size_in_bytes) {
316 if (test_done_) 385 if (test_done_)
317 Crash(); 386 Crash();
318 387
319 if (!callback_fired_) { 388 if (!callback_fired_) {
320 memset(sample_buffer, 0, buffer_size_in_bytes); 389 memset(sample_buffer, 0, buffer_size_in_bytes);
321 core_interface_->CallOnMainThread(0, test_callback_, kMagicValue); 390 core_interface_->CallOnMainThread(0, test_callback_, kMagicValue);
322 callback_fired_ = true; 391 callback_fired_ = true;
323 } 392 }
324 } 393 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_audio.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698