| 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_AUDIO_IO_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_IO_H_ |
| 6 #define MEDIA_AUDIO_AUDIO_IO_H_ | 6 #define MEDIA_AUDIO_AUDIO_IO_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "media/base/audio_bus.h" | 10 #include "media/base/audio_bus.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 // Because we support more audio streams than physically available channels | 42 // Because we support more audio streams than physically available channels |
| 43 // a given AudioOutputStream might or might not talk directly to hardware. | 43 // a given AudioOutputStream might or might not talk directly to hardware. |
| 44 // An audio stream allocates several buffers for audio data and calls | 44 // An audio stream allocates several buffers for audio data and calls |
| 45 // AudioSourceCallback::OnMoreData() periodically to fill these buffers, | 45 // AudioSourceCallback::OnMoreData() periodically to fill these buffers, |
| 46 // as the data is written to the audio device. Size of each packet is determined | 46 // as the data is written to the audio device. Size of each packet is determined |
| 47 // by |samples_per_packet| specified in AudioParameters when the stream is | 47 // by |samples_per_packet| specified in AudioParameters when the stream is |
| 48 // created. | 48 // created. |
| 49 | 49 |
| 50 namespace media { | 50 namespace media { |
| 51 | 51 |
| 52 struct MEDIA_EXPORT AudioTimestamp { |
| 53 AudioTimestamp() = default; |
| 54 int64_t frames; |
| 55 int64_t ticks; // Obtained from base::TimeTicks::ToInternalValue(). |
| 56 }; |
| 57 |
| 58 // Used in unittests. |
| 59 inline bool operator==(const AudioTimestamp& one, const AudioTimestamp& other) { |
| 60 return one.ticks == other.ticks && one.frames == other.frames; |
| 61 } |
| 62 |
| 52 class MEDIA_EXPORT AudioOutputStream { | 63 class MEDIA_EXPORT AudioOutputStream { |
| 53 public: | 64 public: |
| 54 // Audio sources must implement AudioSourceCallback. This interface will be | 65 // Audio sources must implement AudioSourceCallback. This interface will be |
| 55 // called in a random thread which very likely is a high priority thread. Do | 66 // called in a random thread which very likely is a high priority thread. Do |
| 56 // not rely on using this thread TLS or make calls that alter the thread | 67 // not rely on using this thread TLS or make calls that alter the thread |
| 57 // itself such as creating Windows or initializing COM. | 68 // itself such as creating Windows or initializing COM. |
| 58 class MEDIA_EXPORT AudioSourceCallback { | 69 class MEDIA_EXPORT AudioSourceCallback { |
| 59 public: | 70 public: |
| 60 virtual ~AudioSourceCallback() {} | 71 virtual ~AudioSourceCallback() {} |
| 61 | 72 |
| 62 // Provide more data by fully filling |dest|. The source will return | 73 // Provide more data by fully filling |dest|. The source will return |
| 63 // the number of frames it filled. |total_bytes_delay| contains current | 74 // the number of frames it filled. |total_bytes_delay| contains current |
| 64 // number of bytes of delay buffered by the AudioOutputStream. | 75 // number of bytes of delay buffered by the AudioOutputStream. |
| 65 // |frames_skipped| contains the number of frames skipped by the consumer. | 76 // |frames_skipped| contains the number of frames skipped by the consumer. |
| 66 virtual int OnMoreData(AudioBus* dest, | 77 // |timestamp| if provided, contains timestamp of the currently audible |
| 67 uint32_t total_bytes_delay, | 78 // signal. |
| 68 uint32_t frames_skipped) = 0; | 79 virtual int OnMoreData( |
| 80 AudioBus* dest, |
| 81 uint32_t total_bytes_delay, |
| 82 uint32_t frames_skipped, |
| 83 const AudioTimestamp& output_timestamp = AudioTimestamp()) = 0; |
| 69 | 84 |
| 70 // There was an error while playing a buffer. Audio source cannot be | 85 // There was an error while playing a buffer. Audio source cannot be |
| 71 // destroyed yet. No direct action needed by the AudioStream, but it is | 86 // destroyed yet. No direct action needed by the AudioStream, but it is |
| 72 // a good place to stop accumulating sound data since is is likely that | 87 // a good place to stop accumulating sound data since is is likely that |
| 73 // playback will not continue. | 88 // playback will not continue. |
| 74 virtual void OnError(AudioOutputStream* stream) = 0; | 89 virtual void OnError(AudioOutputStream* stream) = 0; |
| 75 }; | 90 }; |
| 76 | 91 |
| 77 virtual ~AudioOutputStream() {} | 92 virtual ~AudioOutputStream() {} |
| 78 | 93 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // Returns the Automatic Gain Control (AGC) state. | 183 // Returns the Automatic Gain Control (AGC) state. |
| 169 virtual bool GetAutomaticGainControl() = 0; | 184 virtual bool GetAutomaticGainControl() = 0; |
| 170 | 185 |
| 171 // Returns the current muting state for the microphone. | 186 // Returns the current muting state for the microphone. |
| 172 virtual bool IsMuted() = 0; | 187 virtual bool IsMuted() = 0; |
| 173 }; | 188 }; |
| 174 | 189 |
| 175 } // namespace media | 190 } // namespace media |
| 176 | 191 |
| 177 #endif // MEDIA_AUDIO_AUDIO_IO_H_ | 192 #endif // MEDIA_AUDIO_AUDIO_IO_H_ |
| OLD | NEW |