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

Side by Side Diff: media/audio/mac/audio_low_latency_input_mac_unittest.cc

Issue 9854031: Replace size_t with int in a few media classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 9 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
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/environment.h" 6 #include "base/environment.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/test/test_timeouts.h" 8 #include "base/test/test_timeouts.h"
9 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
10 #include "media/audio/audio_io.h" 10 #include "media/audio/audio_io.h"
(...skipping 26 matching lines...) Expand all
37 37
38 // This audio sink implementation should be used for manual tests only since 38 // This audio sink implementation should be used for manual tests only since
39 // the recorded data is stored on a raw binary data file. 39 // the recorded data is stored on a raw binary data file.
40 // The last test (WriteToFileAudioSink) - which is disabled by default - 40 // The last test (WriteToFileAudioSink) - which is disabled by default -
41 // can use this audio sink to store the captured data on a file for offline 41 // can use this audio sink to store the captured data on a file for offline
42 // analysis. 42 // analysis.
43 class WriteToFileAudioSink : public AudioInputStream::AudioInputCallback { 43 class WriteToFileAudioSink : public AudioInputStream::AudioInputCallback {
44 public: 44 public:
45 // Allocate space for ~10 seconds of data @ 48kHz in stereo: 45 // Allocate space for ~10 seconds of data @ 48kHz in stereo:
46 // 2 bytes per sample, 2 channels, 10ms @ 48kHz, 10 seconds <=> 1920000 bytes. 46 // 2 bytes per sample, 2 channels, 10ms @ 48kHz, 10 seconds <=> 1920000 bytes.
47 static const size_t kMaxBufferSize = 2 * 2 * 480 * 100 * 10; 47 static const int kMaxBufferSize = 2 * 2 * 480 * 100 * 10;
48 48
49 explicit WriteToFileAudioSink(const char* file_name) 49 explicit WriteToFileAudioSink(const char* file_name)
50 : buffer_(0, kMaxBufferSize), 50 : buffer_(0, kMaxBufferSize),
51 file_(fopen(file_name, "wb")), 51 file_(fopen(file_name, "wb")),
52 bytes_to_write_(0) { 52 bytes_to_write_(0) {
53 } 53 }
54 54
55 virtual ~WriteToFileAudioSink() { 55 virtual ~WriteToFileAudioSink() {
56 size_t bytes_written = 0; 56 int bytes_written = 0;
57 while (bytes_written < bytes_to_write_) { 57 while (bytes_written < bytes_to_write_) {
58 const uint8* chunk; 58 const uint8* chunk;
59 size_t chunk_size; 59 int chunk_size;
60 60
61 // Stop writing if no more data is available. 61 // Stop writing if no more data is available.
62 if (!buffer_.GetCurrentChunk(&chunk, &chunk_size)) 62 if (!buffer_.GetCurrentChunk(&chunk, &chunk_size))
63 break; 63 break;
64 64
65 // Write recorded data chunk to the file and prepare for next chunk. 65 // Write recorded data chunk to the file and prepare for next chunk.
66 fwrite(chunk, 1, chunk_size, file_); 66 fwrite(chunk, 1, chunk_size, file_);
67 buffer_.Seek(chunk_size); 67 buffer_.Seek(chunk_size);
68 bytes_written += chunk_size; 68 bytes_written += chunk_size;
69 } 69 }
(...skipping 11 matching lines...) Expand all
81 bytes_to_write_ += size; 81 bytes_to_write_ += size;
82 } 82 }
83 } 83 }
84 84
85 virtual void OnClose(AudioInputStream* stream) {} 85 virtual void OnClose(AudioInputStream* stream) {}
86 virtual void OnError(AudioInputStream* stream, int code) {} 86 virtual void OnError(AudioInputStream* stream, int code) {}
87 87
88 private: 88 private:
89 media::SeekableBuffer buffer_; 89 media::SeekableBuffer buffer_;
90 FILE* file_; 90 FILE* file_;
91 size_t bytes_to_write_; 91 int bytes_to_write_;
92 }; 92 };
93 93
94 class MacAudioInputTest : public testing::Test { 94 class MacAudioInputTest : public testing::Test {
95 protected: 95 protected:
96 MacAudioInputTest() : audio_manager_(AudioManager::Create()) {} 96 MacAudioInputTest() : audio_manager_(AudioManager::Create()) {}
97 virtual ~MacAudioInputTest() {} 97 virtual ~MacAudioInputTest() {}
98 98
99 // Convenience method which ensures that we are not running on the build 99 // Convenience method which ensures that we are not running on the build
100 // bots and that at least one valid input device can be found. 100 // bots and that at least one valid input device can be found.
101 bool CanRunAudioTests() { 101 bool CanRunAudioTests() {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 fprintf(stderr, " Sample rate: %d\n", fs); 300 fprintf(stderr, " Sample rate: %d\n", fs);
301 WriteToFileAudioSink file_sink(file_name); 301 WriteToFileAudioSink file_sink(file_name);
302 fprintf(stderr, " >> Speak into the mic while recording...\n"); 302 fprintf(stderr, " >> Speak into the mic while recording...\n");
303 ais->Start(&file_sink); 303 ais->Start(&file_sink);
304 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); 304 base::PlatformThread::Sleep(TestTimeouts::action_timeout());
305 ais->Stop(); 305 ais->Stop();
306 fprintf(stderr, " >> Recording has stopped.\n"); 306 fprintf(stderr, " >> Recording has stopped.\n");
307 ais->Close(); 307 ais->Close();
308 } 308 }
309 309
OLDNEW
« no previous file with comments | « media/audio/linux/alsa_output_unittest.cc ('k') | media/audio/win/audio_low_latency_input_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698