Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 // the WebAudio rendering pipe line on the web thread. | 78 // the WebAudio rendering pipe line on the web thread. |
| 79 void RequestRenderOnWebThread(size_t frames_requested, | 79 void RequestRenderOnWebThread(size_t frames_requested, |
| 80 size_t frames_to_render, | 80 size_t frames_to_render, |
| 81 double delay, | 81 double delay, |
| 82 double delay_timestamp, | 82 double delay_timestamp, |
| 83 size_t prior_frames_skipped); | 83 size_t prior_frames_skipped); |
| 84 | 84 |
| 85 virtual void Start(); | 85 virtual void Start(); |
| 86 virtual void Stop(); | 86 virtual void Stop(); |
| 87 | 87 |
| 88 size_t CallbackBufferSize() const { return callback_buffer_size_; } | 88 // Getters must be accessed from the main thread. |
| 89 bool IsPlaying() { return is_playing_; } | 89 size_t CallbackBufferSize() const; |
| 90 bool IsPlaying(); | |
|
nhiroki
2017/05/02 01:42:51
bool IsPlaying() const; ?
| |
| 90 | 91 |
| 92 // TODO(hongchan): this should not be accssed from the main thread. | |
| 91 double SampleRate() const { return web_audio_device_->SampleRate(); } | 93 double SampleRate() const { return web_audio_device_->SampleRate(); } |
| 92 | 94 |
| 93 // Returns the audio buffer size in frames used by the underlying audio | 95 // Returns the audio buffer size in frames used by the underlying audio |
| 94 // hardware. | 96 // hardware. Must be accssed from the main thread. |
| 95 int FramesPerBuffer() const { return web_audio_device_->FramesPerBuffer(); } | 97 int FramesPerBuffer() const; |
| 96 | 98 |
| 97 // The information from the actual audio hardware. (via Platform::current) | 99 // The information from the actual audio hardware. (via Platform::current) |
| 98 static float HardwareSampleRate(); | 100 static float HardwareSampleRate(); |
| 99 static unsigned long MaxChannelCount(); | 101 static unsigned long MaxChannelCount(); |
| 100 | 102 |
| 101 private: | 103 private: |
| 102 // Check if the buffer size chosen by the WebAudioDevice is too large. | 104 // Check if the buffer size chosen by the WebAudioDevice is too large. |
| 103 bool CheckBufferSize(); | 105 bool CheckBufferSize(); |
| 104 | 106 |
| 105 size_t HardwareBufferSize(); | 107 size_t HardwareBufferSize(); |
| 106 | 108 |
| 107 bool IsRenderingThread(); | 109 bool IsRenderingThread(); |
| 108 | 110 |
| 111 // Accessed by the main thread. | |
| 109 std::unique_ptr<WebAudioDevice> web_audio_device_; | 112 std::unique_ptr<WebAudioDevice> web_audio_device_; |
| 110 const unsigned number_of_output_channels_; | 113 const unsigned number_of_output_channels_; |
| 111 size_t callback_buffer_size_; | 114 size_t callback_buffer_size_; |
| 112 bool is_playing_; | 115 bool is_playing_; |
| 113 | 116 |
| 114 // Rendering thread for WebAudio graph. | 117 // Accessed by device and rendering threads: resolves the buffer size mismatch |
| 118 // between the WebAudio engine and the callback function from the actual audio | |
| 119 // device. | |
| 120 std::unique_ptr<PushPullFIFO> fifo_; | |
| 121 | |
| 122 // Accessed by the device thread. Rendering thread for WebAudio graph. | |
| 115 std::unique_ptr<WebThread> rendering_thread_; | 123 std::unique_ptr<WebThread> rendering_thread_; |
| 116 | 124 |
| 117 // Accessed by both threads: resolves the buffer size mismatch between the | |
| 118 // WebAudio engine and the callback function from the actual audio device. | |
| 119 std::unique_ptr<PushPullFIFO> fifo_; | |
| 120 | |
| 121 // Accessed by device thread: to pass the data from FIFO to the device. | 125 // Accessed by device thread: to pass the data from FIFO to the device. |
| 122 RefPtr<AudioBus> output_bus_; | 126 RefPtr<AudioBus> output_bus_; |
| 123 | 127 |
| 124 // Accessed by rendering thread: to push the rendered result from WebAudio | 128 // Accessed by rendering thread: to push the rendered result from WebAudio |
| 125 // graph into the FIFO. | 129 // graph into the FIFO. |
| 126 RefPtr<AudioBus> render_bus_; | 130 RefPtr<AudioBus> render_bus_; |
| 127 | 131 |
| 128 // Accessed by rendering thread: the render callback function of WebAudio | 132 // Accessed by rendering thread: the render callback function of WebAudio |
| 129 // engine. (i.e. DestinationNode) | 133 // engine. (i.e. DestinationNode) |
| 130 AudioIOCallback& callback_; | 134 AudioIOCallback& callback_; |
| 131 | 135 |
| 132 // Accessed by rendering thread. | 136 // Accessed by rendering thread. |
| 133 size_t frames_elapsed_; | 137 size_t frames_elapsed_; |
| 134 }; | 138 }; |
| 135 | 139 |
| 136 } // namespace blink | 140 } // namespace blink |
| 137 | 141 |
| 138 #endif // AudioDestination_h | 142 #endif // AudioDestination_h |
| OLD | NEW |