| 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 "base/memory/scoped_vector.h" | |
| 9 #include "base/process/process.h" | 8 #include "base/process/process.h" |
| 10 #include "base/sync_socket.h" | 9 #include "base/sync_socket.h" |
| 11 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 12 #include "media/audio/audio_input_controller.h" | 11 #include "media/audio/audio_input_controller.h" |
| 13 #include "media/audio/audio_parameters.h" | |
| 14 #include "media/base/audio_bus.h" | |
| 15 | 12 |
| 16 #if defined(OS_POSIX) | 13 #if defined(OS_POSIX) |
| 17 #include "base/file_descriptor_posix.h" | 14 #include "base/file_descriptor_posix.h" |
| 18 #endif | 15 #endif |
| 19 | 16 |
| 20 namespace base { | 17 namespace base { |
| 21 class SharedMemory; | 18 class SharedMemory; |
| 22 } | 19 } |
| 23 | 20 |
| 24 namespace content { | 21 namespace content { |
| 25 // A AudioInputController::SyncWriter implementation using SyncSocket. This | 22 // A AudioInputController::SyncWriter implementation using SyncSocket. This |
| 26 // is used by AudioInputController to provide a low latency data source for | 23 // is used by AudioInputController to provide a low latency data source for |
| 27 // transmitting audio packets between the browser process and the renderer | 24 // transmitting audio packets between the browser process and the renderer |
| 28 // process. | 25 // process. |
| 29 class AudioInputSyncWriter : public media::AudioInputController::SyncWriter { | 26 class AudioInputSyncWriter : public media::AudioInputController::SyncWriter { |
| 30 public: | 27 public: |
| 31 explicit AudioInputSyncWriter(base::SharedMemory* shared_memory, | 28 explicit AudioInputSyncWriter(base::SharedMemory* shared_memory, |
| 32 int shared_memory_segment_count, | 29 int shared_memory_segment_count); |
| 33 const media::AudioParameters& params); | |
| 34 | 30 |
| 35 virtual ~AudioInputSyncWriter(); | 31 virtual ~AudioInputSyncWriter(); |
| 36 | 32 |
| 37 // media::AudioInputController::SyncWriter implementation. | 33 // media::AudioOutputController::SyncWriter implementation. |
| 38 virtual void UpdateRecordedBytes(uint32 bytes) OVERRIDE; | 34 virtual void UpdateRecordedBytes(uint32 bytes) OVERRIDE; |
| 39 virtual void Write(const media::AudioBus* data, | 35 virtual uint32 Write(const void* data, |
| 40 double volume, | 36 uint32 size, |
| 41 bool key_pressed) OVERRIDE; | 37 double volume, |
| 38 bool key_pressed) OVERRIDE; |
| 42 virtual void Close() OVERRIDE; | 39 virtual void Close() OVERRIDE; |
| 43 | 40 |
| 44 bool Init(); | 41 bool Init(); |
| 45 bool PrepareForeignSocketHandle(base::ProcessHandle process_handle, | 42 bool PrepareForeignSocketHandle(base::ProcessHandle process_handle, |
| 46 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
| 47 base::SyncSocket::Handle* foreign_handle); | 44 base::SyncSocket::Handle* foreign_handle); |
| 48 #else | 45 #else |
| 49 base::FileDescriptor* foreign_handle); | 46 base::FileDescriptor* foreign_handle); |
| 50 #endif | 47 #endif |
| 51 | 48 |
| 52 private: | 49 private: |
| 53 base::SharedMemory* shared_memory_; | 50 base::SharedMemory* shared_memory_; |
| 54 uint32 shared_memory_segment_size_; | 51 uint32 shared_memory_segment_size_; |
| 55 uint32 shared_memory_segment_count_; | 52 uint32 shared_memory_segment_count_; |
| 56 uint32 current_segment_id_; | 53 uint32 current_segment_id_; |
| 57 | 54 |
| 58 // Socket for transmitting audio data. | 55 // Socket for transmitting audio data. |
| 59 scoped_ptr<base::CancelableSyncSocket> socket_; | 56 scoped_ptr<base::CancelableSyncSocket> socket_; |
| 60 | 57 |
| 61 // Socket to be used by the renderer. The reference is released after | 58 // Socket to be used by the renderer. The reference is released after |
| 62 // PrepareForeignSocketHandle() is called and ran successfully. | 59 // PrepareForeignSocketHandle() is called and ran successfully. |
| 63 scoped_ptr<base::CancelableSyncSocket> foreign_socket_; | 60 scoped_ptr<base::CancelableSyncSocket> foreign_socket_; |
| 64 | 61 |
| 65 // The time of the creation of this object. | 62 // The time of the creation of this object. |
| 66 base::Time creation_time_; | 63 base::Time creation_time_; |
| 67 | 64 |
| 68 // The time of the last Write call. | 65 // The time of the last Write call. |
| 69 base::Time last_write_time_; | 66 base::Time last_write_time_; |
| 70 | 67 |
| 71 // Size in bytes of each audio bus. | |
| 72 const int audio_bus_memory_size_; | |
| 73 | |
| 74 // Vector of audio buses allocated during construction and deleted in the | |
| 75 // destructor. | |
| 76 ScopedVector<media::AudioBus> audio_buses_; | |
| 77 | |
| 78 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputSyncWriter); | 68 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputSyncWriter); |
| 79 }; | 69 }; |
| 80 | 70 |
| 81 } // namespace content | 71 } // namespace content |
| 82 | 72 |
| 83 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_ | 73 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_ |
| OLD | NEW |