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

Side by Side Diff: media/audio/win/audio_output_win_unittest.cc

Issue 10830268: Allow audio system to handle synchronized low-latency audio I/O (Closed) Base URL: svn://svn.chromium.org/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 | « media/audio/win/audio_low_latency_output_win_unittest.cc ('k') | media/base/audio_bus.h » ('j') | 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 <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/file_util.h" 10 #include "base/file_util.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 had_error_(0) { 47 had_error_(0) {
48 } 48 }
49 // AudioSourceCallback::OnMoreData implementation: 49 // AudioSourceCallback::OnMoreData implementation:
50 virtual int OnMoreData(AudioBus* audio_bus, 50 virtual int OnMoreData(AudioBus* audio_bus,
51 AudioBuffersState buffers_state) { 51 AudioBuffersState buffers_state) {
52 ++callback_count_; 52 ++callback_count_;
53 // Touch the channel memory value to make sure memory is good. 53 // Touch the channel memory value to make sure memory is good.
54 audio_bus->Zero(); 54 audio_bus->Zero();
55 return audio_bus->frames(); 55 return audio_bus->frames();
56 } 56 }
57 virtual int OnMoreIOData(AudioBus* source,
58 AudioBus* dest,
59 AudioBuffersState buffers_state) {
60 NOTREACHED();
61 return 0;
62 }
57 // AudioSourceCallback::OnError implementation: 63 // AudioSourceCallback::OnError implementation:
58 virtual void OnError(AudioOutputStream* stream, int code) { 64 virtual void OnError(AudioOutputStream* stream, int code) {
59 ++had_error_; 65 ++had_error_;
60 } 66 }
61 // Returns how many times OnMoreData() has been called. 67 // Returns how many times OnMoreData() has been called.
62 int callback_count() const { 68 int callback_count() const {
63 return callback_count_; 69 return callback_count_;
64 } 70 }
65 // Returns how many times the OnError callback was called. 71 // Returns how many times the OnError callback was called.
66 int had_error() const { 72 int had_error() const {
(...skipping 28 matching lines...) Expand all
95 } 101 }
96 private: 102 private:
97 int laggy_after_buffer_; 103 int laggy_after_buffer_;
98 int lag_in_ms_; 104 int lag_in_ms_;
99 }; 105 };
100 106
101 class MockAudioSource : public AudioOutputStream::AudioSourceCallback { 107 class MockAudioSource : public AudioOutputStream::AudioSourceCallback {
102 public: 108 public:
103 MOCK_METHOD2(OnMoreData, int(AudioBus* audio_bus, 109 MOCK_METHOD2(OnMoreData, int(AudioBus* audio_bus,
104 AudioBuffersState buffers_state)); 110 AudioBuffersState buffers_state));
111 MOCK_METHOD3(OnMoreIOData, int(AudioBus* source,
112 AudioBus* dest,
113 AudioBuffersState buffers_state));
105 MOCK_METHOD2(OnError, void(AudioOutputStream* stream, int code)); 114 MOCK_METHOD2(OnError, void(AudioOutputStream* stream, int code));
106 115
107 static int ClearData(AudioBus* audio_bus, AudioBuffersState buffers_state) { 116 static int ClearData(AudioBus* audio_bus, AudioBuffersState buffers_state) {
108 audio_bus->Zero(); 117 audio_bus->Zero();
109 return audio_bus->frames(); 118 return audio_bus->frames();
110 } 119 }
111 }; 120 };
112 121
113 // Helper class to memory map an entire file. The mapping is read-only. Don't 122 // Helper class to memory map an entire file. The mapping is read-only. Don't
114 // use for gigabyte-sized files. Attempts to write to this memory generate 123 // use for gigabyte-sized files. Attempts to write to this memory generate
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 591
583 // AudioSourceCallback::OnMoreData implementation: 592 // AudioSourceCallback::OnMoreData implementation:
584 virtual int OnMoreData(AudioBus* audio_bus, 593 virtual int OnMoreData(AudioBus* audio_bus,
585 AudioBuffersState buffers_state) { 594 AudioBuffersState buffers_state) {
586 socket_->Send(&buffers_state, sizeof(buffers_state)); 595 socket_->Send(&buffers_state, sizeof(buffers_state));
587 uint32 size = socket_->Receive(data_.get(), data_size_); 596 uint32 size = socket_->Receive(data_.get(), data_size_);
588 DCHECK_EQ(static_cast<size_t>(size) % sizeof(*audio_bus_->channel(0)), 0U); 597 DCHECK_EQ(static_cast<size_t>(size) % sizeof(*audio_bus_->channel(0)), 0U);
589 audio_bus_->CopyTo(audio_bus); 598 audio_bus_->CopyTo(audio_bus);
590 return audio_bus_->frames(); 599 return audio_bus_->frames();
591 } 600 }
601 virtual int OnMoreIOData(AudioBus* source,
602 AudioBus* dest,
603 AudioBuffersState buffers_state) {
604 NOTREACHED();
605 return 0;
606 }
592 // AudioSourceCallback::OnError implementation: 607 // AudioSourceCallback::OnError implementation:
593 virtual void OnError(AudioOutputStream* stream, int code) { 608 virtual void OnError(AudioOutputStream* stream, int code) {
594 } 609 }
595 610
596 private: 611 private:
597 base::SyncSocket* socket_; 612 base::SyncSocket* socket_;
598 int data_size_; 613 int data_size_;
599 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_; 614 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> data_;
600 scoped_ptr<AudioBus> audio_bus_; 615 scoped_ptr<AudioBus> audio_bus_;
601 }; 616 };
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 oas->Start(&source); 701 oas->Start(&source);
687 702
688 ::WaitForSingleObject(thread, INFINITE); 703 ::WaitForSingleObject(thread, INFINITE);
689 ::CloseHandle(thread); 704 ::CloseHandle(thread);
690 705
691 oas->Stop(); 706 oas->Stop();
692 oas->Close(); 707 oas->Close();
693 } 708 }
694 709
695 } // namespace media 710 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/win/audio_low_latency_output_win_unittest.cc ('k') | media/base/audio_bus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698