| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/lock.h" | 10 #include "base/lock.h" |
| 11 #include "media/audio/audio_output.h" | 11 #include "media/audio/audio_output.h" |
| 12 #include "media/base/seekable_buffer.h" |
| 12 | 13 |
| 13 // An audio source that produces a pure sinusoidal tone. | 14 // An audio source that produces a pure sinusoidal tone. |
| 14 class SineWaveAudioSource : public AudioOutputStream::AudioSourceCallback { | 15 class SineWaveAudioSource : public AudioOutputStream::AudioSourceCallback { |
| 15 public: | 16 public: |
| 16 enum Format { | 17 enum Format { |
| 17 FORMAT_8BIT_LINEAR_PCM, | 18 FORMAT_8BIT_LINEAR_PCM, |
| 18 FORMAT_16BIT_LINEAR_PCM, | 19 FORMAT_16BIT_LINEAR_PCM, |
| 19 }; | 20 }; |
| 20 // |channels| is the number of audio channels, |freq| is the frequency in | 21 // |channels| is the number of audio channels, |freq| is the frequency in |
| 21 // hertz and it has to be less than half of the sampling frequency | 22 // hertz and it has to be less than half of the sampling frequency |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // Implementation of AudioSourceCallback. | 71 // Implementation of AudioSourceCallback. |
| 71 virtual uint32 OnMoreData(AudioOutputStream* stream, | 72 virtual uint32 OnMoreData(AudioOutputStream* stream, |
| 72 void* dest, uint32 max_size, uint32 pending_bytes); | 73 void* dest, uint32 max_size, uint32 pending_bytes); |
| 73 virtual void OnClose(AudioOutputStream* stream); | 74 virtual void OnClose(AudioOutputStream* stream); |
| 74 virtual void OnError(AudioOutputStream* stream, int code); | 75 virtual void OnError(AudioOutputStream* stream, int code); |
| 75 | 76 |
| 76 // Discard all buffered data and reset to initial state. | 77 // Discard all buffered data and reset to initial state. |
| 77 void ClearAll(); | 78 void ClearAll(); |
| 78 | 79 |
| 79 private: | 80 private: |
| 80 // Defines the unit of playback. We own the memory pointed by |buffer|. | |
| 81 struct Packet { | |
| 82 char* buffer; | |
| 83 uint32 size; | |
| 84 }; | |
| 85 | |
| 86 // Free acquired resources. | 81 // Free acquired resources. |
| 87 void CleanUp(); | 82 void CleanUp(); |
| 88 | 83 |
| 89 typedef std::list<Packet> PacketList; | 84 media::SeekableBuffer buffer_; |
| 90 PacketList packets_; | 85 // Serialize access to |buffer_| using this lock. |
| 91 uint32 buffered_bytes_; | 86 Lock buffer_lock_; |
| 92 uint32 front_buffer_consumed_; | |
| 93 // Serialize access to packets_ and buffered_bytes_ using this lock. | |
| 94 Lock lock_; | |
| 95 }; | 87 }; |
| 96 | 88 |
| 97 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ | 89 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ |
| OLD | NEW |