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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
| 10 #include <memory> |
| 11 |
10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
11 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
12 #include "media/audio/audio_io.h" | 14 #include "media/audio/audio_io.h" |
13 #include "media/base/audio_converter.h" | 15 #include "media/base/audio_converter.h" |
14 #include "media/base/seekable_buffer.h" | 16 #include "media/base/seekable_buffer.h" |
15 | 17 |
16 namespace media { | 18 namespace media { |
17 | 19 |
18 class WavAudioHandler; | 20 class WavAudioHandler; |
19 | 21 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 uint32_t frames_skipped) override; | 67 uint32_t frames_skipped) override; |
66 void OnError(AudioOutputStream* stream) override; | 68 void OnError(AudioOutputStream* stream) override; |
67 | 69 |
68 private: | 70 private: |
69 AudioParameters params_; | 71 AudioParameters params_; |
70 base::FilePath path_to_wav_file_; | 72 base::FilePath path_to_wav_file_; |
71 | 73 |
72 // The WAV data at |path_to_wav_file_| is read into memory and kept here. | 74 // The WAV data at |path_to_wav_file_| is read into memory and kept here. |
73 // This memory needs to survive for the lifetime of |wav_audio_handler_|, | 75 // This memory needs to survive for the lifetime of |wav_audio_handler_|, |
74 // so declare it first. Do not access this member directly. | 76 // so declare it first. Do not access this member directly. |
75 scoped_ptr<char[]> raw_wav_data_; | 77 std::unique_ptr<char[]> raw_wav_data_; |
76 | 78 |
77 scoped_ptr<WavAudioHandler> wav_audio_handler_; | 79 std::unique_ptr<WavAudioHandler> wav_audio_handler_; |
78 scoped_ptr<AudioConverter> file_audio_converter_; | 80 std::unique_ptr<AudioConverter> file_audio_converter_; |
79 int wav_file_read_pos_; | 81 int wav_file_read_pos_; |
80 bool load_failed_; | 82 bool load_failed_; |
81 | 83 |
82 // Provides audio data from wav_audio_handler_ into the file audio converter. | 84 // Provides audio data from wav_audio_handler_ into the file audio converter. |
83 double ProvideInput(AudioBus* audio_bus, | 85 double ProvideInput(AudioBus* audio_bus, |
84 base::TimeDelta buffer_delay) override; | 86 base::TimeDelta buffer_delay) override; |
85 | 87 |
86 // Loads the wav file on the first OnMoreData invocation. | 88 // Loads the wav file on the first OnMoreData invocation. |
87 void LoadWavFile(const base::FilePath& path_to_wav_file); | 89 void LoadWavFile(const base::FilePath& path_to_wav_file); |
88 }; | 90 }; |
89 | 91 |
90 class BeepingSource : public AudioOutputStream::AudioSourceCallback { | 92 class BeepingSource : public AudioOutputStream::AudioSourceCallback { |
91 public: | 93 public: |
92 BeepingSource(const AudioParameters& params); | 94 BeepingSource(const AudioParameters& params); |
93 ~BeepingSource() override; | 95 ~BeepingSource() override; |
94 | 96 |
95 // Implementation of AudioSourceCallback. | 97 // Implementation of AudioSourceCallback. |
96 int OnMoreData(AudioBus* audio_bus, | 98 int OnMoreData(AudioBus* audio_bus, |
97 uint32_t total_bytes_delay, | 99 uint32_t total_bytes_delay, |
98 uint32_t frames_skipped) override; | 100 uint32_t frames_skipped) override; |
99 void OnError(AudioOutputStream* stream) override; | 101 void OnError(AudioOutputStream* stream) override; |
100 | 102 |
101 static void BeepOnce(); | 103 static void BeepOnce(); |
102 private: | 104 private: |
103 int buffer_size_; | 105 int buffer_size_; |
104 scoped_ptr<uint8_t[]> buffer_; | 106 std::unique_ptr<uint8_t[]> buffer_; |
105 AudioParameters params_; | 107 AudioParameters params_; |
106 base::TimeTicks last_callback_time_; | 108 base::TimeTicks last_callback_time_; |
107 base::TimeDelta interval_from_last_beep_; | 109 base::TimeDelta interval_from_last_beep_; |
108 int beep_duration_in_buffers_; | 110 int beep_duration_in_buffers_; |
109 int beep_generated_in_buffers_; | 111 int beep_generated_in_buffers_; |
110 int beep_period_in_frames_; | 112 int beep_period_in_frames_; |
111 }; | 113 }; |
112 | 114 |
113 } // namespace media | 115 } // namespace media |
114 | 116 |
115 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ | 117 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ |
OLD | NEW |