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 #ifndef MEDIA_AUDIO_SIMPLE_SOURCES_H_ | 5 #ifndef MEDIA_AUDIO_SIMPLE_SOURCES_H_ |
6 #define MEDIA_AUDIO_SIMPLE_SOURCES_H_ | 6 #define MEDIA_AUDIO_SIMPLE_SOURCES_H_ |
7 | 7 |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "media/audio/audio_io.h" | 10 #include "media/audio/audio_io.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 // |sample_freq| or else you will get aliasing. | 24 // |sample_freq| or else you will get aliasing. |
25 SineWaveAudioSource(int channels, double freq, double sample_freq); | 25 SineWaveAudioSource(int channels, double freq, double sample_freq); |
26 ~SineWaveAudioSource() override; | 26 ~SineWaveAudioSource() override; |
27 | 27 |
28 // Return up to |cap| samples of data via OnMoreData(). Use Reset() to | 28 // Return up to |cap| samples of data via OnMoreData(). Use Reset() to |
29 // allow more data to be served. | 29 // allow more data to be served. |
30 void CapSamples(int cap); | 30 void CapSamples(int cap); |
31 void Reset(); | 31 void Reset(); |
32 | 32 |
33 // Implementation of AudioSourceCallback. | 33 // Implementation of AudioSourceCallback. |
34 int OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) override; | 34 int OnMoreData(AudioBus* audio_bus, |
| 35 uint32_t total_bytes_delay, |
| 36 uint32_t frames_skipped) override; |
35 void OnError(AudioOutputStream* stream) override; | 37 void OnError(AudioOutputStream* stream) override; |
36 | 38 |
37 // The number of OnMoreData() and OnError() calls respectively. | 39 // The number of OnMoreData() and OnError() calls respectively. |
38 int callbacks() { return callbacks_; } | 40 int callbacks() { return callbacks_; } |
39 int errors() { return errors_; } | 41 int errors() { return errors_; } |
40 | 42 |
41 protected: | 43 protected: |
42 int channels_; | 44 int channels_; |
43 double f_; | 45 double f_; |
44 int time_state_; | 46 int time_state_; |
45 int cap_; | 47 int cap_; |
46 int callbacks_; | 48 int callbacks_; |
47 int errors_; | 49 int errors_; |
48 base::Lock time_lock_; | 50 base::Lock time_lock_; |
49 }; | 51 }; |
50 | 52 |
51 class MEDIA_EXPORT FileSource : public AudioOutputStream::AudioSourceCallback, | 53 class MEDIA_EXPORT FileSource : public AudioOutputStream::AudioSourceCallback, |
52 public AudioConverter::InputCallback { | 54 public AudioConverter::InputCallback { |
53 public: | 55 public: |
54 FileSource(const AudioParameters& params, | 56 FileSource(const AudioParameters& params, |
55 const base::FilePath& path_to_wav_file); | 57 const base::FilePath& path_to_wav_file); |
56 ~FileSource() override; | 58 ~FileSource() override; |
57 | 59 |
58 // Implementation of AudioSourceCallback. | 60 // Implementation of AudioSourceCallback. |
59 int OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) override; | 61 int OnMoreData(AudioBus* audio_bus, |
| 62 uint32_t total_bytes_delay, |
| 63 uint32_t frames_skipped) override; |
60 void OnError(AudioOutputStream* stream) override; | 64 void OnError(AudioOutputStream* stream) override; |
61 | 65 |
62 private: | 66 private: |
63 AudioParameters params_; | 67 AudioParameters params_; |
64 base::FilePath path_to_wav_file_; | 68 base::FilePath path_to_wav_file_; |
65 | 69 |
66 // The WAV data at |path_to_wav_file_| is read into memory and kept here. | 70 // The WAV data at |path_to_wav_file_| is read into memory and kept here. |
67 // This memory needs to survive for the lifetime of |wav_audio_handler_|, | 71 // This memory needs to survive for the lifetime of |wav_audio_handler_|, |
68 // so declare it first. Do not access this member directly. | 72 // so declare it first. Do not access this member directly. |
69 scoped_ptr<char[]> raw_wav_data_; | 73 scoped_ptr<char[]> raw_wav_data_; |
(...skipping 10 matching lines...) Expand all Loading... |
80 // Loads the wav file on the first OnMoreData invocation. | 84 // Loads the wav file on the first OnMoreData invocation. |
81 void LoadWavFile(const base::FilePath& path_to_wav_file); | 85 void LoadWavFile(const base::FilePath& path_to_wav_file); |
82 }; | 86 }; |
83 | 87 |
84 class BeepingSource : public AudioOutputStream::AudioSourceCallback { | 88 class BeepingSource : public AudioOutputStream::AudioSourceCallback { |
85 public: | 89 public: |
86 BeepingSource(const AudioParameters& params); | 90 BeepingSource(const AudioParameters& params); |
87 ~BeepingSource() override; | 91 ~BeepingSource() override; |
88 | 92 |
89 // Implementation of AudioSourceCallback. | 93 // Implementation of AudioSourceCallback. |
90 int OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) override; | 94 int OnMoreData(AudioBus* audio_bus, |
| 95 uint32_t total_bytes_delay, |
| 96 uint32_t frames_skipped) override; |
91 void OnError(AudioOutputStream* stream) override; | 97 void OnError(AudioOutputStream* stream) override; |
92 | 98 |
93 static void BeepOnce(); | 99 static void BeepOnce(); |
94 private: | 100 private: |
95 int buffer_size_; | 101 int buffer_size_; |
96 scoped_ptr<uint8[]> buffer_; | 102 scoped_ptr<uint8[]> buffer_; |
97 AudioParameters params_; | 103 AudioParameters params_; |
98 base::TimeTicks last_callback_time_; | 104 base::TimeTicks last_callback_time_; |
99 base::TimeDelta interval_from_last_beep_; | 105 base::TimeDelta interval_from_last_beep_; |
100 int beep_duration_in_buffers_; | 106 int beep_duration_in_buffers_; |
101 int beep_generated_in_buffers_; | 107 int beep_generated_in_buffers_; |
102 int beep_period_in_frames_; | 108 int beep_period_in_frames_; |
103 }; | 109 }; |
104 | 110 |
105 } // namespace media | 111 } // namespace media |
106 | 112 |
107 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ | 113 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ |
OLD | NEW |