| 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 CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 size_t shared_memory_size, | 43 size_t shared_memory_size, |
| 44 int shared_memory_segment_count, | 44 int shared_memory_segment_count, |
| 45 const media::AudioParameters& params); | 45 const media::AudioParameters& params); |
| 46 | 46 |
| 47 ~AudioInputSyncWriter() override; | 47 ~AudioInputSyncWriter() override; |
| 48 | 48 |
| 49 // media::AudioInputController::SyncWriter implementation. | 49 // media::AudioInputController::SyncWriter implementation. |
| 50 void Write(const media::AudioBus* data, | 50 void Write(const media::AudioBus* data, |
| 51 double volume, | 51 double volume, |
| 52 bool key_pressed, | 52 bool key_pressed, |
| 53 uint32_t hardware_delay_bytes) override; | 53 base::TimeDelta delay, |
| 54 base::TimeTicks delay_timestamp) override; |
| 54 void Close() override; | 55 void Close() override; |
| 55 | 56 |
| 56 bool Init(); | 57 bool Init(); |
| 57 bool PrepareForeignSocket(base::ProcessHandle process_handle, | 58 bool PrepareForeignSocket(base::ProcessHandle process_handle, |
| 58 base::SyncSocket::TransitDescriptor* descriptor); | 59 base::SyncSocket::TransitDescriptor* descriptor); |
| 59 | 60 |
| 60 protected: | 61 protected: |
| 61 // Socket for transmitting audio data. | 62 // Socket for transmitting audio data. |
| 62 std::unique_ptr<base::CancelableSyncSocket> socket_; | 63 std::unique_ptr<base::CancelableSyncSocket> socket_; |
| 63 | 64 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 76 | 77 |
| 77 // Virtual function for native logging to be able to override in tests. | 78 // Virtual function for native logging to be able to override in tests. |
| 78 virtual void AddToNativeLog(const std::string& message); | 79 virtual void AddToNativeLog(const std::string& message); |
| 79 | 80 |
| 80 // Push |data| and metadata to |audio_buffer_fifo_|. Returns true if | 81 // Push |data| and metadata to |audio_buffer_fifo_|. Returns true if |
| 81 // successful. Logs error and returns false if the fifo already reached the | 82 // successful. Logs error and returns false if the fifo already reached the |
| 82 // maximum size. | 83 // maximum size. |
| 83 bool PushDataToFifo(const media::AudioBus* data, | 84 bool PushDataToFifo(const media::AudioBus* data, |
| 84 double volume, | 85 double volume, |
| 85 bool key_pressed, | 86 bool key_pressed, |
| 86 uint32_t hardware_delay_bytes); | 87 base::TimeDelta delay, |
| 88 base::TimeTicks delay_timestamp); |
| 87 | 89 |
| 88 // Writes as much data as possible from the fifo (|overflow_buses_|) to the | 90 // Writes as much data as possible from the fifo (|overflow_buses_|) to the |
| 89 // shared memory ring buffer. Returns true if all operations were successful, | 91 // shared memory ring buffer. Returns true if all operations were successful, |
| 90 // otherwise false. | 92 // otherwise false. |
| 91 bool WriteDataFromFifoToSharedMemory(); | 93 bool WriteDataFromFifoToSharedMemory(); |
| 92 | 94 |
| 93 // Write audio parameters to current segment in shared memory. | 95 // Write audio parameters to current segment in shared memory. |
| 94 void WriteParametersToCurrentSegment(double volume, | 96 void WriteParametersToCurrentSegment(double volume, |
| 95 bool key_pressed, | 97 bool key_pressed, |
| 96 uint32_t hardware_delay_bytes); | 98 base::TimeDelta delay, |
| 99 base::TimeTicks delay_timestamp); |
| 97 | 100 |
| 98 // Signals over the socket that data has been written to the current segment. | 101 // Signals over the socket that data has been written to the current segment. |
| 99 // Updates counters and returns true if successful. Logs error and returns | 102 // Updates counters and returns true if successful. Logs error and returns |
| 100 // false if failure. | 103 // false if failure. |
| 101 bool SignalDataWrittenAndUpdateCounters(); | 104 bool SignalDataWrittenAndUpdateCounters(); |
| 102 | 105 |
| 103 uint8_t* shared_memory_; | 106 uint8_t* shared_memory_; |
| 104 uint32_t shared_memory_segment_size_; | 107 uint32_t shared_memory_segment_size_; |
| 105 uint32_t shared_memory_segment_count_; | 108 uint32_t shared_memory_segment_count_; |
| 106 uint32_t current_segment_id_; | 109 uint32_t current_segment_id_; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 ScopedVector<media::AudioBus> audio_buses_; | 155 ScopedVector<media::AudioBus> audio_buses_; |
| 153 | 156 |
| 154 // Fifo for audio that is used in case there isn't room in the shared memory. | 157 // Fifo for audio that is used in case there isn't room in the shared memory. |
| 155 // This can for example happen under load when the consumer side is starved. | 158 // This can for example happen under load when the consumer side is starved. |
| 156 // It should ideally be rare, but we need to guarantee that the data arrives | 159 // It should ideally be rare, but we need to guarantee that the data arrives |
| 157 // since audio processing such as echo cancelling requires that to perform | 160 // since audio processing such as echo cancelling requires that to perform |
| 158 // properly. | 161 // properly. |
| 159 ScopedVector<media::AudioBus> overflow_buses_; | 162 ScopedVector<media::AudioBus> overflow_buses_; |
| 160 struct OverflowParams { | 163 struct OverflowParams { |
| 161 double volume; | 164 double volume; |
| 162 uint32_t hardware_delay_bytes; | 165 base::TimeDelta delay; |
| 166 base::TimeTicks delay_timestamp; |
| 163 bool key_pressed; | 167 bool key_pressed; |
| 164 }; | 168 }; |
| 165 std::deque<OverflowParams> overflow_params_; | 169 std::deque<OverflowParams> overflow_params_; |
| 166 | 170 |
| 167 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputSyncWriter); | 171 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputSyncWriter); |
| 168 }; | 172 }; |
| 169 | 173 |
| 170 } // namespace content | 174 } // namespace content |
| 171 | 175 |
| 172 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_ | 176 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_ |
| OLD | NEW |