| 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> | 10 #include <memory> |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 int cap_; | 51 int cap_; |
| 52 int callbacks_; | 52 int callbacks_; |
| 53 int errors_; | 53 int errors_; |
| 54 base::Lock time_lock_; | 54 base::Lock time_lock_; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 class MEDIA_EXPORT FileSource : public AudioOutputStream::AudioSourceCallback, | 57 class MEDIA_EXPORT FileSource : public AudioOutputStream::AudioSourceCallback, |
| 58 public AudioConverter::InputCallback { | 58 public AudioConverter::InputCallback { |
| 59 public: | 59 public: |
| 60 FileSource(const AudioParameters& params, | 60 FileSource(const AudioParameters& params, |
| 61 const base::FilePath& path_to_wav_file); | 61 const base::FilePath& path_to_wav_file, |
| 62 bool loop); |
| 62 ~FileSource() override; | 63 ~FileSource() override; |
| 63 | 64 |
| 64 // Implementation of AudioSourceCallback. | 65 // Implementation of AudioSourceCallback. |
| 65 int OnMoreData(AudioBus* audio_bus, | 66 int OnMoreData(AudioBus* audio_bus, |
| 66 uint32_t total_bytes_delay, | 67 uint32_t total_bytes_delay, |
| 67 uint32_t frames_skipped) override; | 68 uint32_t frames_skipped) override; |
| 68 void OnError(AudioOutputStream* stream) override; | 69 void OnError(AudioOutputStream* stream) override; |
| 69 | 70 |
| 70 private: | 71 private: |
| 71 AudioParameters params_; | 72 AudioParameters params_; |
| 72 base::FilePath path_to_wav_file_; | 73 base::FilePath path_to_wav_file_; |
| 73 | 74 |
| 74 // The WAV data at |path_to_wav_file_| is read into memory and kept here. | 75 // The WAV data at |path_to_wav_file_| is read into memory and kept here. |
| 75 // This memory needs to survive for the lifetime of |wav_audio_handler_|, | 76 // This memory needs to survive for the lifetime of |wav_audio_handler_|, |
| 76 // so declare it first. Do not access this member directly. | 77 // so declare it first. Do not access this member directly. |
| 77 std::unique_ptr<char[]> raw_wav_data_; | 78 std::unique_ptr<char[]> raw_wav_data_; |
| 78 | 79 |
| 79 std::unique_ptr<WavAudioHandler> wav_audio_handler_; | 80 std::unique_ptr<WavAudioHandler> wav_audio_handler_; |
| 80 std::unique_ptr<AudioConverter> file_audio_converter_; | 81 std::unique_ptr<AudioConverter> file_audio_converter_; |
| 81 int wav_file_read_pos_; | 82 int wav_file_read_pos_; |
| 82 bool load_failed_; | 83 bool load_failed_; |
| 84 bool looping_; |
| 83 | 85 |
| 84 // Provides audio data from wav_audio_handler_ into the file audio converter. | 86 // Provides audio data from wav_audio_handler_ into the file audio converter. |
| 85 double ProvideInput(AudioBus* audio_bus, uint32_t frames_delayed) override; | 87 double ProvideInput(AudioBus* audio_bus, uint32_t frames_delayed) override; |
| 86 | 88 |
| 87 // Loads the wav file on the first OnMoreData invocation. | 89 // Loads the wav file on the first OnMoreData invocation. |
| 88 void LoadWavFile(const base::FilePath& path_to_wav_file); | 90 void LoadWavFile(const base::FilePath& path_to_wav_file); |
| 91 |
| 92 // Rewinds the player to the start of the loaded wav file. |
| 93 void Rewind(); |
| 89 }; | 94 }; |
| 90 | 95 |
| 91 class BeepingSource : public AudioOutputStream::AudioSourceCallback { | 96 class BeepingSource : public AudioOutputStream::AudioSourceCallback { |
| 92 public: | 97 public: |
| 93 BeepingSource(const AudioParameters& params); | 98 BeepingSource(const AudioParameters& params); |
| 94 ~BeepingSource() override; | 99 ~BeepingSource() override; |
| 95 | 100 |
| 96 // Implementation of AudioSourceCallback. | 101 // Implementation of AudioSourceCallback. |
| 97 int OnMoreData(AudioBus* audio_bus, | 102 int OnMoreData(AudioBus* audio_bus, |
| 98 uint32_t total_bytes_delay, | 103 uint32_t total_bytes_delay, |
| 99 uint32_t frames_skipped) override; | 104 uint32_t frames_skipped) override; |
| 100 void OnError(AudioOutputStream* stream) override; | 105 void OnError(AudioOutputStream* stream) override; |
| 101 | 106 |
| 102 static void BeepOnce(); | 107 static void BeepOnce(); |
| 103 private: | 108 private: |
| 104 int buffer_size_; | 109 int buffer_size_; |
| 105 std::unique_ptr<uint8_t[]> buffer_; | 110 std::unique_ptr<uint8_t[]> buffer_; |
| 106 AudioParameters params_; | 111 AudioParameters params_; |
| 107 base::TimeTicks last_callback_time_; | 112 base::TimeTicks last_callback_time_; |
| 108 base::TimeDelta interval_from_last_beep_; | 113 base::TimeDelta interval_from_last_beep_; |
| 109 int beep_duration_in_buffers_; | 114 int beep_duration_in_buffers_; |
| 110 int beep_generated_in_buffers_; | 115 int beep_generated_in_buffers_; |
| 111 int beep_period_in_frames_; | 116 int beep_period_in_frames_; |
| 112 }; | 117 }; |
| 113 | 118 |
| 114 } // namespace media | 119 } // namespace media |
| 115 | 120 |
| 116 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ | 121 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ |
| OLD | NEW |