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 <windows.h> | 5 #include <windows.h> |
6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/memory/aligned_memory.h" | 10 #include "base/memory/aligned_memory.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 // This class allows to find out if the callbacks are occurring as | 40 // This class allows to find out if the callbacks are occurring as |
41 // expected and if any error has been reported. | 41 // expected and if any error has been reported. |
42 class TestSourceBasic : public AudioOutputStream::AudioSourceCallback { | 42 class TestSourceBasic : public AudioOutputStream::AudioSourceCallback { |
43 public: | 43 public: |
44 TestSourceBasic() | 44 TestSourceBasic() |
45 : callback_count_(0), | 45 : callback_count_(0), |
46 had_error_(0) { | 46 had_error_(0) { |
47 } | 47 } |
48 // AudioSourceCallback::OnMoreData implementation: | 48 // AudioSourceCallback::OnMoreData implementation: |
49 int OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) override { | 49 int OnMoreData(AudioBus* audio_bus, |
| 50 uint32_t total_bytes_delay, |
| 51 uint32_t frames_skipped) override { |
50 ++callback_count_; | 52 ++callback_count_; |
51 // Touch the channel memory value to make sure memory is good. | 53 // Touch the channel memory value to make sure memory is good. |
52 audio_bus->Zero(); | 54 audio_bus->Zero(); |
53 return audio_bus->frames(); | 55 return audio_bus->frames(); |
54 } | 56 } |
55 // AudioSourceCallback::OnError implementation: | 57 // AudioSourceCallback::OnError implementation: |
56 void OnError(AudioOutputStream* stream) override { ++had_error_; } | 58 void OnError(AudioOutputStream* stream) override { ++had_error_; } |
57 // Returns how many times OnMoreData() has been called. | 59 // Returns how many times OnMoreData() has been called. |
58 int callback_count() const { | 60 int callback_count() const { |
59 return callback_count_; | 61 return callback_count_; |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 : socket_(socket) { | 509 : socket_(socket) { |
508 // Setup AudioBus wrapping data we'll receive over the sync socket. | 510 // Setup AudioBus wrapping data we'll receive over the sync socket. |
509 data_size_ = AudioBus::CalculateMemorySize(params); | 511 data_size_ = AudioBus::CalculateMemorySize(params); |
510 data_.reset(static_cast<float*>( | 512 data_.reset(static_cast<float*>( |
511 base::AlignedAlloc(data_size_, AudioBus::kChannelAlignment))); | 513 base::AlignedAlloc(data_size_, AudioBus::kChannelAlignment))); |
512 audio_bus_ = AudioBus::WrapMemory(params, data_.get()); | 514 audio_bus_ = AudioBus::WrapMemory(params, data_.get()); |
513 } | 515 } |
514 ~SyncSocketSource() override {} | 516 ~SyncSocketSource() override {} |
515 | 517 |
516 // AudioSourceCallback::OnMoreData implementation: | 518 // AudioSourceCallback::OnMoreData implementation: |
517 int OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) override { | 519 int OnMoreData(AudioBus* audio_bus, |
| 520 uint32_t total_bytes_delay, |
| 521 uint32_t frames_skipped) override { |
518 socket_->Send(&total_bytes_delay, sizeof(total_bytes_delay)); | 522 socket_->Send(&total_bytes_delay, sizeof(total_bytes_delay)); |
519 uint32 size = socket_->Receive(data_.get(), data_size_); | 523 uint32 size = socket_->Receive(data_.get(), data_size_); |
520 DCHECK_EQ(static_cast<size_t>(size) % sizeof(*audio_bus_->channel(0)), 0U); | 524 DCHECK_EQ(static_cast<size_t>(size) % sizeof(*audio_bus_->channel(0)), 0U); |
521 audio_bus_->CopyTo(audio_bus); | 525 audio_bus_->CopyTo(audio_bus); |
522 return audio_bus_->frames(); | 526 return audio_bus_->frames(); |
523 } | 527 } |
524 | 528 |
525 // AudioSourceCallback::OnError implementation: | 529 // AudioSourceCallback::OnError implementation: |
526 void OnError(AudioOutputStream* stream) override {} | 530 void OnError(AudioOutputStream* stream) override {} |
527 | 531 |
(...skipping 30 matching lines...) Expand all Loading... |
558 | 562 |
559 SineWaveAudioSource sine(1, ctx.sine_freq, ctx.sample_rate); | 563 SineWaveAudioSource sine(1, ctx.sine_freq, ctx.sample_rate); |
560 const int kTwoSecFrames = ctx.sample_rate * 2; | 564 const int kTwoSecFrames = ctx.sample_rate * 2; |
561 | 565 |
562 uint32 total_bytes_delay = 0; | 566 uint32 total_bytes_delay = 0; |
563 int times = 0; | 567 int times = 0; |
564 for (int ix = 0; ix < kTwoSecFrames; ix += ctx.frames) { | 568 for (int ix = 0; ix < kTwoSecFrames; ix += ctx.frames) { |
565 if (ctx.socket->Receive(&total_bytes_delay, sizeof(total_bytes_delay)) == 0) | 569 if (ctx.socket->Receive(&total_bytes_delay, sizeof(total_bytes_delay)) == 0) |
566 break; | 570 break; |
567 if ((times > 0) && (total_bytes_delay < 1000)) __debugbreak(); | 571 if ((times > 0) && (total_bytes_delay < 1000)) __debugbreak(); |
568 sine.OnMoreData(audio_bus.get(), total_bytes_delay); | 572 sine.OnMoreData(audio_bus.get(), total_bytes_delay, 0); |
569 ctx.socket->Send(data.get(), ctx.packet_size_bytes); | 573 ctx.socket->Send(data.get(), ctx.packet_size_bytes); |
570 ++times; | 574 ++times; |
571 } | 575 } |
572 | 576 |
573 return 0; | 577 return 0; |
574 } | 578 } |
575 | 579 |
576 // Test the basic operation of AudioOutputStream used with a SyncSocket. | 580 // Test the basic operation of AudioOutputStream used with a SyncSocket. |
577 // The emphasis is to verify that it is possible to feed data to the audio | 581 // The emphasis is to verify that it is possible to feed data to the audio |
578 // layer using a source based on SyncSocket. In a real situation we would | 582 // layer using a source based on SyncSocket. In a real situation we would |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 oas->Start(&source); | 620 oas->Start(&source); |
617 | 621 |
618 ::WaitForSingleObject(thread, INFINITE); | 622 ::WaitForSingleObject(thread, INFINITE); |
619 ::CloseHandle(thread); | 623 ::CloseHandle(thread); |
620 | 624 |
621 oas->Stop(); | 625 oas->Stop(); |
622 oas->Close(); | 626 oas->Close(); |
623 } | 627 } |
624 | 628 |
625 } // namespace media | 629 } // namespace media |
OLD | NEW |